Javascript 将事件发送到外部组件文件夹?我已经做了一些事情,但它没有侦听emite事件";“功能”;?
这是我的文件夹结构,我需要将src/component/header/app.component.header.html中发生的“feature”事件发送到src/app.component.htmlJavascript 将事件发送到外部组件文件夹?我已经做了一些事情,但它没有侦听emite事件";“功能”;?,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,这是我的文件夹结构,我需要将src/component/header/app.component.header.html中发生的“feature”事件发送到src/app.component.html <div class="row"> <div class="col-xl-12"> <app-header (feature)="onNavigation($event)" ></app-header> </div>
<div class="row">
<div class="col-xl-12">
<app-header (feature)="onNavigation($event)" ></app-header>
</div>
</div>
src/component/header/app.component.header.ts
<li class="nav-item ">
<a class="nav-link" href="#" (click)=" onSelect('recipes')" >Recipes <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" (click)="onSelect('shopping-list')" >Shopping List</a>
</li
>
@Output() feature =new EventEmitter<string>();
onSelect(featured:string){
this.feature.emit(featured);
}
src/component/header/app.component.header.ts
<li class="nav-item ">
<a class="nav-link" href="#" (click)=" onSelect('recipes')" >Recipes <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" (click)="onSelect('shopping-list')" >Shopping List</a>
</li
>
@Output() feature =new EventEmitter<string>();
onSelect(featured:string){
this.feature.emit(featured);
}
@Output()功能=新的EventEmitter();
onSelect(特色:字符串){
this.feature.emit(featured);
}
src/app.component.html
<div class="row">
<div class="col-xl-12">
<app-header (feature)="onNavigation($event)" ></app-header>
</div>
</div>
不要使用“String”类型,而是使用“String”(所有小写字母)。字符串(以及数字、布尔值等)类型指的是非基本装箱对象,不应使用。更正此错误后,您的代码工作正常
//Wrong
@Output() feature =new EventEmitter<String>();
//Correct
@Output() feature =new EventEmitter<string>();
不要使用“String”类型,而是使用“String”(所有小写字母)。字符串(以及数字、布尔值等)类型指的是非基本装箱对象,不应使用。更正此错误后,您的代码工作正常
//Wrong
@Output() feature =new EventEmitter<String>();
//Correct
@Output() feature =new EventEmitter<string>();
请显示您的app.component.ts i.e onnavigation功能,并尝试在OnSelect功能上的chrome开发工具中放置断点。请显示您的app.component.ts i.e onnavigation功能,并尝试在OnSelect功能上的chrome开发工具中放置断点。我已在stackblitz中添加了代码。似乎对我有用。查看并检查控制台。我在stackblitz中添加了代码。似乎对我有用。查看并检查控制台。