我是Angular 9的新手。
我正试图将事件从孩子传播到父母,但是我不明白我做错了什么,因为父母根本没有得到事件。
这是我的孩子cmp html
<a (click)="view(profilo.id)" class="btn btn-simple btn-info btn-icon like"></a>
儿童ts
@Component({
selector: 'app-gestione-profili',
templateUrl: './gestione-profili.component.html',
styleUrls: ['./gestione-profili.component.scss']
})
export class GestioneProfiliComponent implements OnInit {
@Output() vedi = new EventEmitter<string>();
id=0;
view(id){
//console.log(id+'figlio')
this.id = id;
this.informazioni=true;
this.vedi.emit(id);
}
}
这是我的父母html
<app-gestione-profili (vedi)="mostra($event)"></app-gestione-profili>
和父Ts
@Component({
selector: 'app-pannello-controllo',
templateUrl: 'pannello-controllo.component.html',
styleUrls: ['./pannello-controllo.component.scss']
})
export class PannelloControlloComponent implements OnInit {
constructor() { }
id=0;
ngOnInit(): void {
}
mostra(id){
this.id=id;
console.log(id+ 'padre')
}
}
有什么不好的主意吗?
答案 0 :(得分:0)
好吧,这是我的愚蠢错误...我没有在应用程序路由中添加父组件的路由-因此html从未被读取,事件也从未传播- 我已经通过在应用程序路由中添加路径解决了它 还是谢谢大家