Angular 事件发射器工作一次,但不是第二次
我有一个变量,它控制对话框是否显示,它第一次工作,但第二次不工作,emit excutes,但不再调用receiveing函数 父类:Angular 事件发射器工作一次,但不是第二次,angular,typescript,events,dialog,angular-event-emitter,Angular,Typescript,Events,Dialog,Angular Event Emitter,我有一个变量,它控制对话框是否显示,它第一次工作,但第二次不工作,emit excutes,但不再调用receiveing函数 父类: isLogin :boolean ; constructor(...){ this.isLogin = false; } receiveNotification(notification: boolean): void { this.isLogin = notification; } 父html: <login-dial
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的,但不确定,这里出了什么问题?可能是因为您正在发送一个真实值,但您正在检查父模板!真的是假的
根据您当前的逻辑,您应该在父模板中发出一个假值或将条件更改为*ngIf=isLogin。这可能是因为您在父模板上发出了一个真值,但您正在检查!真的是假的
根据当前逻辑,您应该在父模板中发出假值或将条件更改为*ngIf=isLogin。尝试使用hidden而不是ngIf,因为ngIf从DOM中删除组件,但hidden只是隐藏它
<login-dialog [hidden]="isLogin" name="{{name}}"...></login-dialog>
尝试使用hidden而不是ngIf,因为ngIf从DOM中删除组件,而hidden只是隐藏它
<login-dialog [hidden]="isLogin" name="{{name}}"...></login-dialog>