我有这个变量来控制对话框是否显示,它在第一次时有效,但在第二次时无效,发出执行但不再调用接收函数。
父类:
isLogin :boolean ;
constructor(...){
this.isLogin = false;
}
receiveNotification(notification: boolean): void {
this.isLogin = notification;
}
父级 html:
<login-dialog *ngIf="!isLogin" name="{{name}}" (notify)="receiveNotification($event)"></login-dialog>
在子类中: 我有一个函数,当触发调用 emit 和 emit 确实被调用时,它不会第二次触发父级上的函数
@Output() notify = new EventEmitter<any>();
exampleFunction(){
this.notify.emit(true);
}
我想这可能与 ngIf 有关但不确定,这里有什么问题?
最佳答案
这可能是因为您正在发出一个真值,但在父模板上您正在检查 !true
而它是 false。
根据您当前的逻辑,您应该发出假值或将条件更改为父模板中的 *ngIf="isLogin"
。
关于angular - 事件发射器工作一次但不是第二次 Angular 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57199726/