I am currently using Angular 7 and I am trying to achieve a functionality where the text on a button changes every time it is clicked, toggling between 'login' and 'logout'.
Below is the code snippet I have been working on:
typescript file:
export class HeaderComponent implements OnInit {
text: string;
constructor() {
this.loadDataFromApi();
}
ngOnInit() {
if (this.token == null) {
this.text = 'login';
alert(this.text);
} else if (this.token) {
this.token = 'logout';
alert(this.text);
}
}
}
An alert saying undefined is being displayed
html file:
<button type="button"> {{text}}</button>