]>
Commit | Line | Data |
---|---|---|
98b01bac C |
1 | import { Component, OnInit } from 'angular2/core'; |
2 | import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router'; | |
dc8bc31b | 3 | |
98b01bac C |
4 | import { VideosService } from '../../services/videos.service'; |
5 | import { Video } from '../../models/video'; | |
dc8bc31b C |
6 | |
7 | @Component({ | |
8 | selector: 'my-videos-list', | |
9 | styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ], | |
10 | templateUrl: 'app/angular/videos/components/list/videos-list.component.html', | |
11 | directives: [ ROUTER_DIRECTIVES ] | |
12 | }) | |
13 | ||
14 | export class VideosListComponent implements OnInit { | |
15 | videos: Video[]; | |
16 | ||
98b01bac C |
17 | private search: string; |
18 | ||
dc8bc31b | 19 | constructor( |
98b01bac C |
20 | private _videosService: VideosService, |
21 | routeParams: RouteParams | |
22 | ) { | |
23 | this.search = routeParams.get('search'); | |
24 | } | |
dc8bc31b C |
25 | |
26 | ngOnInit() { | |
27 | this.getVideos(); | |
28 | } | |
29 | ||
30 | getVideos() { | |
98b01bac C |
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( | |
dc8bc31b C |
40 | videos => this.videos = videos, |
41 | error => alert(error) | |
42 | ); | |
43 | } | |
44 | ||
45 | removeVideo(id: string) { | |
46 | this._videosService.removeVideo(id).subscribe( | |
47 | status => this.getVideos(), | |
48 | error => alert(error) | |
49 | ) | |
50 | } | |
51 | ||
52 | } |