aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/videos/components/list/videos-list.component.ts
blob: e5af87448ac2a50fca4387416816ea48ee137a6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {Component, OnInit} from 'angular2/core';
import {ROUTER_DIRECTIVES} from 'angular2/router';

import {VideosService} from '../../services/videos.service';
import {Video} from '../../models/video';

@Component({
  selector: 'my-videos-list',
  styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ],
  templateUrl: 'app/angular/videos/components/list/videos-list.component.html',
  directives: [ ROUTER_DIRECTIVES ]
})

export class VideosListComponent implements OnInit {
  videos: Video[];

  constructor(
    private _videosService: VideosService
  ) { }

  ngOnInit() {
    this.getVideos();
  }

  getVideos() {
    this._videosService.getVideos().subscribe(
      videos => this.videos = videos,
      error => alert(error)
    );
  }

  removeVideo(id: string) {
    this._videosService.removeVideo(id).subscribe(
      status => this.getVideos(),
      error => alert(error)
    )
  }

}