diff options
Diffstat (limited to 'client/angular/videos/components/list/videos-list.component.ts')
-rw-r--r-- | client/angular/videos/components/list/videos-list.component.ts | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/client/angular/videos/components/list/videos-list.component.ts b/client/angular/videos/components/list/videos-list.component.ts index e5af87448..eb23ed1ff 100644 --- a/client/angular/videos/components/list/videos-list.component.ts +++ b/client/angular/videos/components/list/videos-list.component.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import {Component, OnInit} from 'angular2/core'; | 1 | import { Component, OnInit } from 'angular2/core'; |
2 | import {ROUTER_DIRECTIVES} from 'angular2/router'; | 2 | import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router'; |
3 | 3 | ||
4 | import {VideosService} from '../../services/videos.service'; | 4 | import { VideosService } from '../../services/videos.service'; |
5 | import {Video} from '../../models/video'; | 5 | import { Video } from '../../models/video'; |
6 | 6 | ||
7 | @Component({ | 7 | @Component({ |
8 | selector: 'my-videos-list', | 8 | selector: 'my-videos-list', |
@@ -14,16 +14,29 @@ import {Video} from '../../models/video'; | |||
14 | export class VideosListComponent implements OnInit { | 14 | export class VideosListComponent implements OnInit { |
15 | videos: Video[]; | 15 | videos: Video[]; |
16 | 16 | ||
17 | private search: string; | ||
18 | |||
17 | constructor( | 19 | constructor( |
18 | private _videosService: VideosService | 20 | private _videosService: VideosService, |
19 | ) { } | 21 | routeParams: RouteParams |
22 | ) { | ||
23 | this.search = routeParams.get('search'); | ||
24 | } | ||
20 | 25 | ||
21 | ngOnInit() { | 26 | ngOnInit() { |
22 | this.getVideos(); | 27 | this.getVideos(); |
23 | } | 28 | } |
24 | 29 | ||
25 | getVideos() { | 30 | getVideos() { |
26 | this._videosService.getVideos().subscribe( | 31 | let observable = null; |
32 | |||
33 | if (this.search !== null) { | ||
34 | observable = this._videosService.searchVideos(this.search); | ||
35 | } else { | ||
36 | observable = this._videosService.getVideos() | ||
37 | } | ||
38 | |||
39 | observable.subscribe( | ||
27 | videos => this.videos = videos, | 40 | videos => this.videos = videos, |
28 | error => alert(error) | 41 | error => alert(error) |
29 | ); | 42 | ); |