First of all thanks for your time.
I am new to Angular 2 and I am trying to understand how to solve this problem I have.
Component Structure:
<parent-component>
<dynamic-button></dynamic-button>
<dynamic-button></dynamic-button>
...
</parent-component>
Child component
export class DynamicButtonComponent {
@Output() clicked: EventEmitter<any> = new EventEmitter<any>();
loading: Boolean = false;
handleClick(event: any) {
this.loading = true;
this.clicked.emit(event);
}
};
When I click on the Dynamic button I am sending an event to the parent. A spinner will be shown next to the button using 'loading' variable. Parent then makes an API call, when the API call is done I would like to send a prop back to the Child component from the parent (which initially send the event) to stop showing the spinner.
Please advise what would be the best/cleanest way to solve this. I thought of having a callback to the event emitter but I read in StackOverflow that it is against Angular 2's principle