javascript - *ngFor | async doesn't work -
there input text each change, service search results. serivce returns : observable contain results. return multiple persons.
tamplate.html:
<input type="text" id="inputsearch"> ... <tr *ngfor="let person of items$ | async" ... ...
code:
import { component ,oninit} '@angular/core'; import {control} '@angular/common'; import {personservice} "./person.service"; import {person} "./person.class"; import {observable} "rxjs/rx" @component({ selector: 'contact-table', moduleid: module.id, templateurl: 'contact-table.component.html', styleurls: ['contact-table.component.css'] }) export class contacttable implements oninit { private items$: observable<person[]>; private inputchanged$:observable<{}>; constructor(private _personservice:personservice) {} public ngoninit() { this.inputchanged$=observable.fromevent(document.getelementbyid("inputsearch"), 'input'); this.items$= this.inputchanged$ .map((event:any)=>event.target.value) .switchmap((value:string) =>{ return this._personservice.getpersons(); <<-- gets here!**** }) .toarray(); this.items$.subscribe((persons:person[])=>{ console.log(persons); <<-- doesn't gets here!**** }); } }
update1:
by günter zöchbauer tip, added menual subscription in last line of method code never excuted , nothing gets logged. idea why?
update2: added full ts file of code.
updated3:
solved - don't know why: ( moved toarray() )
public ngoninit() { this.inputchanged$=observable.fromevent(document.getelementbyid("inputsearch"), 'input'); this.items$= this.inputchanged$ .map((event:any)=>event.target.value) .switchmap((value:string) =>{ return this._personservice.getpersons().toarray(); <<-- moved here }); <<-insead of here. this.items$.subscribe((persons:person[])=>{ console.log(persons); <<-- doesn't gets here!**** });
any idea why made diffrence?
Comments
Post a Comment