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.