Answers for "send event to child component angular"

3

send event to child component angular

Parent-Component

eventsSubject: Subject<void> = new Subject<void>();

emitEventToChild() {
  this.eventsSubject.next();
}


Parent-HTML

<child [events]="eventsSubject.asObservable()"> </child>


Child-Component

private eventsSubscription: Subscription;

@Input() events: Observable<void>;

ngOnInit(){
  this.eventsSubscription = this.events.subscribe(() => doSomething());
}

ngOnDestroy() {
  this.eventsSubscription.unsubscribe();
}
Posted by: Guest on July-21-2020

Code answers related to "send event to child component angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language