I am trying to test ngOnchanges
so I've created a new project and here is my app.component.ts
and .html
app.component.ts:
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnChanges {
@Input() mydata?: string;
ngOnChanges(changes: SimpleChanges) {
console.log(changes); // This does not appear in my console
}
change() {
this.mydata = 'some change here';
}
}
app.component.html
<h1>NG Changes</h1>
Changes: {{ mydata | json }}
<button (click)="change()">Change</button>
Why I'm I not getting any result from ngOnchanges ... It seems like it's not being fired at all.
How can I fix this?