angular - Run Method on FormControl's valueChanges Event -


i have following code angular 2 type-ahead component:

this.question["input"] = new formcontrol(); this.question["input"].valuechanges         .debouncetime(400)         .switchmap(term => this.question['callback'](term))         .subscribe(             data => {                 this.question["options"].length = 0;                 this.question["options"].push(...data);             }         ); 

which working great, attempting add loading animation event, i.e. animation starts when formcontrol's value changes, , ends when data returned.

with said there way tap method chain code such following?

...     .valuechanges     /* start animation or run custom function here */     .switchmap(term => /* run ajax here */)     .subscribe(         data => {             /* end animation here */         }     ); ... 

any assistance appreciated.

this has not been tested, similar code i've used in app... hope helps:

this.question["input"] = new formcontrol(); this.question["input"].valuechanges   .debouncetime(400)   .switchmap(term => this.question['callback'](term))   .subscribe(      data => {         this.question["options"].length = 0;         this.question["options"].push(...data);         this.startanimation();      },      () => {this.completeanimation()}   );  startanimation() {    //start animation code here }  completeanimation() {    //complete animation here. } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -