Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将事件发送到外部组件文件夹?我已经做了一些事情,但它没有侦听emite事件";“功能”;?_Javascript_Html_Angular_Typescript - Fatal编程技术网

Javascript 将事件发送到外部组件文件夹?我已经做了一些事情,但它没有侦听emite事件";“功能”;?

Javascript 将事件发送到外部组件文件夹?我已经做了一些事情,但它没有侦听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>

这是我的文件夹结构,我需要将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>
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中添加了代码。似乎对我有用。查看并检查控制台。