📜  向子组件 angular 发送事件 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:28.431000             🧑  作者: Mango

代码示例1
Parent-Component

eventsSubject: Subject = new Subject();

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


Parent-HTML

 


Child-Component

private eventsSubscription: Subscription;

@Input() events: Observable;

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

ngOnDestroy() {
  this.eventsSubscription.unsubscribe();
}