79352482

Date: 2025-01-13 14:23:49
Score: 1
Natty:
Report link

this is the solition I came with:

import { Component, Inject } from '@angular/core';
import { PLATFORM_ID } from '@angular/core'; 
import { isPlatformBrowser } from '@angular/common'; 

@Component({
  selector: 'app-data-binding',
  imports: [],
  templateUrl: './data-binding.component.html',
  styleUrl: './data-binding.component.css'
})
export class DataBindingComponent {

  firstName: string = "Lulu";
  rollNo: number = 121;
  isActive: boolean = true;
  currentDate: Date = new Date();
  myPlaceholder: string = "Enter your name"
  divColor: string = "bg-primary";
  isBrowser: boolean;

  constructor(@Inject(PLATFORM_ID) platformId: Object) { 
    if(this.isBrowser = isPlatformBrowser(platformId)) {
      this.showWelcomeMessage()
    } 
  } 

  showWelcomeMessage() {
      alert('Welcome');
    }
    
}

I can also use the method elsewhere, like in a button <button class="btn btn-success" (click)="showWelcomeMessage()">Show Welcome Text</button>

Thanks for helping me.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: phos