Angular 当我点击“家长”时,如何将“真”发送给孩子?

Angular 当我点击“家长”时,如何将“真”发送给孩子?,angular,Angular,在child中,我有这样一个: callSalesEntry() { this.callSEntry = true; } 但是它只发射一次。我想我可以帮你 虽然您也可以在子组件中直接使用它,但在这里使用公共服务将是一个很好的实践 首先,您需要在服务中创建发射器,例如 ngOnChanges(){ console.log(this.callSEntry,'aaaa'); } 最后在子组件中订阅更改 constructor(priv

在child中,我有这样一个:

  callSalesEntry() {
            this.callSEntry = true;
        }
但是它只发射一次。

我想我可以帮你

虽然您也可以在子组件中直接使用它,但在这里使用公共服务将是一个很好的实践

首先,您需要在服务中创建发射器,例如

 ngOnChanges(){
        console.log(this.callSEntry,'aaaa');
}
最后在子组件中订阅更改

 constructor(private emitter :EmitterService) {}
 callSalesEntry() {
        this.emitter.callSEntryEmitter.emit(true);
    }

像这样的东西在我看来是正确的,你能创建一个plunker吗
export class EmitterService {
   public callSEntryEmitter:EventEmitter<boolean>=new EventEmitter(); 

}
 constructor(private emitter :EmitterService) {}
 callSalesEntry() {
        this.emitter.callSEntryEmitter.emit(true);
    }
this.emitter.callSEntryEmitter.subscribe(value=>{do something here})