Angular9 角度父组件不侦听子事件
我是新来的 我试图将事件从孩子传播到家长,但我不明白我做错了什么,因为家长根本没有得到事件 这是我的孩子Angular9 角度父组件不侦听子事件,angular9,Angular9,我是新来的 我试图将事件从孩子传播到家长,但我不明白我做错了什么,因为家长根本没有得到事件 这是我的孩子 <a (click)="view(profilo.id)" class="btn btn-simple btn-info btn-icon like"></a> <app-gestione-profili (vedi)="mostra($event)"></app-gestione-pro
<a (click)="view(profilo.id)" class="btn btn-simple btn-info btn-icon like"></a>
<app-gestione-profili (vedi)="mostra($event)"></app-gestione-profili>
知道怎么回事吗?好吧,这是我愚蠢的错误……我没有在应用程序路由中为父组件添加路由——因此html从未被读取,事件也从未传播-- 我通过在应用程序路由中添加路径就解决了这个问题
感谢大家从哪里获得变量
profilo.id
profilo
未定义,这就是为什么在发布的代码中没有结果子ts中不存在profilo
属性,而ngOnInit()
方法也是如此。如果您实现了OnInit,则必须对其进行定义。尝试修复此问题并检查错误是否持续。是否正在执行子对象中的view()方法?父对象上的mostra()方法是否正在执行?能否在mostra()方法中控制台.log(id)并显示输出?
<app-gestione-profili (vedi)="mostra($event)"></app-gestione-profili>
@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')
}
}