My component receives data from a parent component through an input:
Main Component: main.component.ts
<app-sidebar [data]="programData"></app-sidebar>
In the sidebar component, I have the following:
Sidebar Component: sidebar.component.ts
@Input() data: Entry<any>;
The received data contains a unique ID that is used as a parameter in another function to fetch and populate elements on the page. Currently, I am calling this function inside ngOnChanges
, but it gets triggered every time there is a change. Is there a way to call this function only after receiving the data from Input() data
for the first time?
Here is my current implementation:
ngOnChanges() {
this.id = this.data.fields.id;
this.getElements(this.id);
}
EDIT
To clarify, I want to set this.id
only once when receiving the data for the first time. The incoming data is from an API, so it needs to be processed correctly.
Thank you