Click...">

EventEmitter source signal not working in angular 4

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);
}
+6
source share
1 answer

You will 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.

In addition, you need to change your console log, try replacing with console.log("e-" + e)

-2
source

All Articles