here is my code below :
search.component.html
<button (click)="addMe()">Click</button>
search.component.ts
import { Component, Directive, OnInit, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'search-component',
templateUrl: './search.component.html'
})
export class SearchComponent {
@Output() userUpdated = new EventEmitter();
addMe() {
this.userUpdated.emit('my data to emit');
}
}
profile.component.html
<search-component (userUpdated)="handleUserUpdated($event)"></search-component>
profile.component.ts
handleUserUpdated(e) {
console.log('e', e);
}
You should need to declare a type. Use @Output() userUpdated = new EventEmitter<string>();
if you want it to be a string or @Output() userUpdated = new EventEmitter<any>();
if it can be any type.
Also, you need to change your console log, try swapping to console.log("e-" + e)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With