I have a parent component with the following code in the parent.component.html:
<app-child [idElement]=(idElement)></app-child>
In the child component, I have the input parameter like this:
@Input() idElement : number;
And also a function called
getSpecs()
I want the getSpecs() function to be executed by the child when the input is modified by the parent. Is that possible?
For that purpose, you have to use the Angular lifecycle hook ngOnChanges.
In your case it would be something like:
ngOnChanges(changes: SimpleChanges) {
if (changes['idElement']) {
// Do your logic here
this.getSpecs()
}
}
The documentation is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With