angular - Return values using EventEmitter angular2 -
i have eventemitter issues event in parent component, want parent component perform series of instructions , result returns caller, this.filteredlist want contain list returned parent component when returns, filteredlist undefined
this de chid component "autocomplete.component.ts:" //when returns in this.changefilter.emit, this.filteredlist undefined:
export class autocompletecomponent implements oninit { ... public filteredlist = []; @output() changefilter = new eventemitter<any>(); filter(){ //this want filteredlist contain list returned other component: this.filteredlist =this.changefilter.emit({query:this.query}); if (filteredlist){ console.log(filteredlist); } }
the template:
<div class="container"> <div class="input-field col s12"> <input id="clienteaut" type="text" class="form-control bs-autocomplete" style="width:300px;" [(ngmodel)]="query" (keyup)="filter()" on-click="filterall()"> <label for="clienteaut"></label> </div> <div class="divlista" *ngif="filteredlist.length > 0" style=""> <div class="divfila" *ngfor="let item of filteredlist"> <ul > <li> <a (click)="select(item)">{{item.codigocliente}} - {{item.nombre}}</a> </li> </ul> </div> </div> </div>
this parent component "busquedacompiadoras.component.ts":
//the function "onchangefilterclientes" return list data, when returns eventemitter of child component this.filteredlist undefined //any ideas?
export class busquedacopiadorascomponent { clientes: array<any> //= []; ngoninit() { this._comunservice.getmarcas() .subscribe((clientesdata) => { this.clientes = clientesdata clientemodel[]; //this.rellenarmarcas(marcasdata); }); } onchangefilterclientes(obj:any):any[]{ this.clientesfilter = this.clientes.filter(c => c.nombre.tostring().tolowercase().indexof(obj.query)>-1); return this.clientesfilter; }
try following:
export class autocompletecomponent implements oninit { ...
@input() public filteredlist = []; @output() changefilter = new eventemitter<any>(); filter(){ //this want filteredlist contain list returned other component: this.changefilter.emit({query:this.query}); }
and in busquedacopiadorascomponent template pass filteredlist below:
[filteredlist]="clientesfilter"
Comments
Post a Comment