Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { Observable } from 'rxjs/Observable';
  4. import { Subject } from 'rxjs/Subject';
  5.  
  6. import { SearchService } from './search.service';
  7. import { Data } from './datatypings';
  8.  
  9. @Component({
  10. moduleId: module.id,
  11. selector: 'casino-search',
  12. templateUrl: 'search.component.html',
  13. styleUrls: [ 'search.component.css' ],
  14. providers: [SearchService]
  15. })
  16.  
  17. export class SearchComponent implements OnInit {
  18.  
  19. data: Observable<Data[]>;
  20.  
  21. private searchTerms = new Subject<String>();
  22.  
  23. constructor(
  24. private searchService: SearchService,
  25. private router: Router) {}
  26. // Push a search term into the observable stream
  27. search(term: string): void {
  28. this.searchTerms.next(term);
  29. }
  30.  
  31. ngOnInit(): void {
  32. this.data = this.searchTerms
  33. .debounceTime(150) // wait for 150ms pause in events
  34. .distinctUntilChanged() // ignore if next search term is same as previous
  35. .switchMap(term => term // switch to new observable each time
  36. // return the http search observable
  37. ? this.searchService.search(term)
  38. // or the observable of empty data if no search term
  39. : Observable.of<Data[]>([]))
  40. .catch(error => {
  41. // TODO: real error handling
  42. console.log(error);
  43. return Observable.of<Data[]>([]);
  44. });
  45. }
  46.  
  47. gotoDetail(data: Data): void {
  48. let link = ['/detail', data.id];
  49. this.router.navigate(link);
  50. }
  51. }
  52.  
  53. app/data/search.component.ts(37,37): error TS2345: Argument of type 'String' is not assignable to parameter of type 'string'.
  54. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement