Matias Celiz
Matias Celiz

Reputation: 322

EventEmitter on @Output don't works

I have a problem with this:

@Output() searchFilter = new EventEmitter<string>();

then

filter() {
this.searchFilter.emit('soy un emit');}

And in the view I call this :

<input type="text" class="form-control" placeholder="Buscar" [(ngModel)]="searchFilter" (input)="filter()" >

In the parent

<app-header (searchFilter)="filter($event)"></app-header>

This code works without problems in other project but now this gives me the following error

ERROR TypeError: this.searchFilter.emit is not a function

Any idea?

Upvotes: 2

Views: 387

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657048

[(ngModel)]="searchFilter"

causes a string from the input element to be assigned to searchFilter and a string doesn't have an emit method.

It's not entirely clear what you try to accomplish to give more concrete advice to fix your problem.

A guess

@Output() searchFilterChange = new EventEmitter<string>();
@Input() searchFilter:string;

filter() {
  this.searchFilterChange.emit('soy un emit');
}
<input type="text" class="form-control" placeholder="Buscar" 
  [ngModel]="searchFilter" (ngModelChange)="filter()" >

Upvotes: 1

Related Questions