最近我为朋友启动了一个项目,我需要使用事件。我以前只用过一次(只是提醒一下)。不幸的是,我似乎无法让父母赶上发射。这是一些代码:
发出的孩子:
@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);
}
});
}
发出的日志存在,但捕获的日志不存在。有任何想法吗?我觉得我做得很好,但我真的迷路了。