来自子组件的 @Output 不会触发 Angular 5 中的 EventEmitter

dev*_*ato 0 eventemitter angular

我尝试将 @Output 与事件发射器一起使用,以在子组件和父组件之间进行通信以传递变量。我遵循了本教程:https ://dzone.com/articles/understanding-output-and-eventemitter-in-angular

我查看了与此相关的不同 stackoverflow 问题,但没有一个适合我的情况。

子 HTML

<button (click)="onLinkedClicked();">Click me</button>
Run Code Online (Sandbox Code Playgroud)

儿童 TS

import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
.
.
.
export class showcaseMenuComponent implements OnInit {
    @Output() public linkedClicked = new EventEmitter<String>();

    constructor() {}

    onLinkedClicked() {
        console.log('on click child');
        this.linkedClicked.emit('collapsed');
    }
}
Run Code Online (Sandbox Code Playgroud)

它打印日志“点击子项”

父 HTML

 <showcase-menu #topNavMenu [showBranding]="false"
     [showSearch]= "false" (onLinkedClicked)="linkToggler($event)"></showcase-menu>
Run Code Online (Sandbox Code Playgroud)

父 TS

.
.
.
 navMenuState: string;
.
.
.
  linkToggler($event) {
    console.log("partent");
    this.navMenuState = $event;
  }
Run Code Online (Sandbox Code Playgroud)

linkToggler() 永远不会被调用。我在控制台中没有任何错误,

jcr*_*oll 5

该事件必须与与输出装饰器关联的属性名称匹配

<showcase-menu #topNavMenu 
               [showBranding]="false"
               [showSearch]= "false"  
               (linkedClicked)="linkToggler($event)">. 
</showcase-menu>
Run Code Online (Sandbox Code Playgroud)