You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
941 B
37 lines
941 B
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Subject } from 'rxjs/Subject';
|
|
import { SearchService } from './search.service';
|
|
|
|
// Observable class extensions
|
|
import 'rxjs/add/operator/switchMap';
|
|
import 'rxjs/add/operator/debounceTime';
|
|
import 'rxjs/add/operator/distinctUntilChanged';
|
|
|
|
@Component({
|
|
selector: 'app-search',
|
|
templateUrl: './search.component.html',
|
|
styleUrls: ['./search.component.css'],
|
|
providers: [SearchService]
|
|
})
|
|
export class SearchComponent implements OnInit {
|
|
results;
|
|
searchTerms = new Subject<string>();
|
|
|
|
constructor(
|
|
private characterSearchService: SearchService,
|
|
) { }
|
|
|
|
findCharacter(name){
|
|
this.searchTerms.next(name);
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.results = this.searchTerms
|
|
.debounceTime(300)
|
|
.distinctUntilChanged()
|
|
.switchMap(name => this.characterSearchService.createAPIObservable(name));
|
|
}
|
|
|
|
}
|