Created
August 31, 2018 09:54
-
-
Save nicowernli/f7d9d29b1dc49896fc1ee219f5d7ba71 to your computer and use it in GitHub Desktop.
The Search Bar Component base
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, OnInit } from '@angular/core'; | |
import { FormControl } from '@angular/forms'; | |
import { Observable } from 'rxjs'; | |
import { switchMap } from 'rxjs/operators'; | |
import { PlanetService } from '../planet.service'; | |
import { Planet } from '../planet'; | |
@Component({ | |
selector: 'app-search-bar', | |
templateUrl: './search-bar.component.html' | |
}) | |
export class SearchBarComponent implements OnInit { | |
planets$: Observable<Planet[]>; | |
search = new FormControl(); | |
constructor(private service: PlanetService) {} | |
ngOnInit() { | |
this.planets$ = this.search.valueChanges.pipe( | |
switchMap<string, Planet[]>(value => this.service.search(value)) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment