我试图发出从父组件到子组件的 bool 更改,但没有成功。
父组件:
isActionComplete: boolean;
deleteUser() {
this.userService.delete();
this.isActionComplete = true;
setTimeout(() => {
this.isPopUpActive = false;
}, 3000);
this.isActionComplete = false;
}
父级 html:
<app-pop-up [isActionComplete]="isActionComplete"></app-pop-up>
子组件:
@Input() isActionComplete: boolean;
子 html:
<div *ngIf="isActionComplete">Complete</div>
如果我更改“isActionComplete: boolean;”到“isActionComplete = true;”在父组件中,它确实更改了子 bool 值的状态,但由于某种原因,当它在“deleteUser”函数中时,它不起作用。
请问有人可以告诉我哪里出了问题吗?
谢谢
最佳答案
我意识到我的问题是什么!这是 setTimeout 引起的问题。我需要将它移到这里:
deleteUser() {
this.userService.delete();
this.isActionComplete = true;
setTimeout(() => {
this.isPopUpActive = false;
this.isActionComplete = false;
}, 3000);
}
希望这对将来的人有所帮助!
关于javascript - Angular 2 函数中的父子 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49796381/