angular - Angular 事件发射问题
问题描述
最近我为朋友启动了一个项目,我需要使用事件。我以前只用过一次(只是提醒一下)。不幸的是,我似乎无法让父母赶上发射。这是一些代码:
发出的孩子:
@Output() reset: EventEmitter<any> = new EventEmitter();
changeRoute(val)
{
if (val.url = '/' && this.tuneholder.getTune() != null)
{
if (this.tuneholder.getTune().type == this.tune.type){
this.SetTune(this.tuneholder.getTune())
this.tuneholder.clearTune();
console.log("Emit");
console.log(this.tune);
this.reset.emit(this.tune);
}
}
这是父html:
<app-playeritem
[tune]="tune"
*ngFor="let tune of tunes"
(reset)='resetTuneVal($event)'>
</app-playeritem>
这是父打字稿:
resetTuneVal(tune:Tune){
console.log("Caught Emit");
console.log(tune);
this.tunes.forEach(elm => {
if (elm.type == tune.type){
this.SetTune(elm, tune);
}
});
}
发出的日志存在,但捕获的日志不存在。有任何想法吗?我觉得我做得很好,但我真的迷路了。
解决方案
所以我想出了我的问题。我在路由器事件中调用了发出。这意味着父级不是我想象的那样,它实际上是路由器的父级。我通过运行检查ngOnInit()
来修复它,因为无论何时加载elem都会自动调用它。
推荐阅读
- python - 奥多。如何将 char 字段迁移到同一模型中的 many2many
- annotations - 如何将带注释的 VCF 文件转换为 MAF?
- deep-learning - “在 PyTorch 中,默认情况下如何初始化层权重和偏差?”的后续行动
- powershell - 使用 Powershell 合并两个 CSV 文件
- pulseaudio - 临时流的体积
- angular - 需要在执行另一个函数之前执行所有函数 - Angular
- python - 打印所有其他行值都小于 0.05 的行 ID
- android - Jfrog Xray 没有恢复 apk 的无 Violatoins/许可证问题
- windows - 为 tel 和 callto 协议注册 Windows 应用程序
- python - 如何在多线程进程中从搁置中“保存”归档数据?