I'm trying to use @Output with the event emitter to communicate between child to parent component to pass a variable. I followed this tutorial: https://dzone.com/articles/understanding-output-and-eventemitter-in-angular
I have taken a look to different stackoverflow questions related to this, but none work for my case.
Child HTML
<button (click)="onLinkedClicked();">Click me</button>
Child 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');
}
}
It prints the log 'on click child'
Parent HTML
<showcase-menu #topNavMenu [showBranding]="false"
[showSearch]= "false" (onLinkedClicked)="linkToggler($event)"></showcase-menu>
Parent TS
.
.
.
navMenuState: string;
.
.
.
linkToggler($event) {
console.log("partent");
this.navMenuState = $event;
}
The linkToggler() never gets called. And I don't have any error in the console,