Last active
June 27, 2018 01:07
-
-
Save cartant/75582f3791714669eefa736c07b5fd95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component } from '@angular/core'; | |
| import { FormBuilder, FormGroup } from '@angular/forms'; | |
| import { Observable } from 'rxjs'; | |
| import { debounceTime, distinctUntilChanged, pluck } from 'rxjs/operators'; | |
| @Component({ | |
| selector: 'some-component', | |
| template: ` | |
| <form [formGroup]="form"> | |
| <input formControlName="term" type="text"> | |
| </form> | |
| <div class="searching" *ngIf="term$ | async as term"> | |
| <span>Searching for {{ term }}</span> | |
| </div> | |
| ` | |
| }) | |
| export class SomeComponent { | |
| form: FormGroup; | |
| term$: Observable<string>; | |
| constructor(formBuilder: FormBuilder) { | |
| this.form = formBuilder.group({ | |
| term: [''] | |
| }); | |
| this.term$ = this.form.valueChanges.pipe( | |
| pluck('term'), | |
| debounceTime(400), | |
| distinctUntilChanged() | |
| ) as Observable<string>; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment