I have two components Parent Component
and Child component
, I have an API that takes place in the Parent component
and the response value is passed to the child component
. currently I am using ngOnChanges
but I want to know how to use Setters
instead.
assume In the ParentComponent
I have the below code:
<ChildComponent [apiResponse]="res" />
and in the ChildComponent
I have this:
@Input() apiResponse: any;
ngOnChanges(changes: SimpleChanges) {
console.log(this.apiResponse)
}
Every time the apiResponse
changed the ngOnChanges
function will fire and prints the value in the console.
if I want to achieve the result but with the use if Setters
. as in other scenario I might have multiple inputs and I don't want ngOnChanges
to get fired every time an input's value changed.