Created
May 10, 2019 13:20
-
-
Save alegut/2aa5daaa39e80724f175afbd100372b6 to your computer and use it in GitHub Desktop.
How to emit an event in angular from parent to child
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private eventsSubscription: any | |
@Input() events: Observable<void>; | |
ngOnInit(){ | |
this.eventsSubscription = this.events.subscribe(() => doSomething()) | |
} | |
ngOnDestroy() { | |
this.eventsSubscription.unsubscribe() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<child [events]="eventsSubject$"> </child> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private eventsSubject: Subject<void> = new Subject<void>(); | |
private eventsSubject$ = this.tabChanged.asObservable(); | |
emitEventToChild() { | |
this.eventsSubject.next() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment