I am setting value from parent component and changing immediately. In child component, change detection execute only once.
Stachblitz code base
Parent Code:HTML
<h1>Parent Component</h1>
<p>Contents of the parent component</p>
<button (click)='parentClickEvt()'>Parent Button</button>
<child [message]="msg" (informParent)="parentWillTakeAction($event)"></child>
Parent Code: TS
msg: string="testing";
parentWillTakeAction(message){
this.messageFromChild = message;
}
parentClickEvt(){
this.msg = "Message from parent to child";
this.msg = "India";
this.msg = "India, ASIA";
this.msg = "JAPAN";
this.msg = "JAPAN, ASIA";
}
Child Component : TS
export class ChildComponent implements OnInit {
@Input() message: string;
@Output() informParent = new EventEmitter();
ngOnChanges(simpleChanges: SimpleChanges) {
console.log(simpleChanges.message.currentValue)
}
}
After executing parentClickEvt method from parent which is changing value 4 times. In Child component, ngOnChanges suppose to execute 4 times. But, it is only executing once with latest value.
Please suggest how ngOnChanges should execute according to all changes