From 0629423ce335137ce77d1ee8fe30fc0eee36d83b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Jul 2016 17:15:14 +0200 Subject: Client: Update to Angular RC4 --- .../videos/video-watch/video-watch.component.ts | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'client/src/app/videos/video-watch') diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts index 99188bfb3..09255de5d 100644 --- a/client/src/app/videos/video-watch/video-watch.component.ts +++ b/client/src/app/videos/video-watch/video-watch.component.ts @@ -1,5 +1,5 @@ -import { Component, ElementRef, OnInit } from '@angular/core'; -import { CanDeactivate, RouteSegment } from '@angular/router'; +import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; @@ -15,7 +15,7 @@ import { WebTorrentService } from './webtorrent.service'; pipes: [ BytesPipe ] }) -export class VideoWatchComponent implements OnInit, CanDeactivate { +export class VideoWatchComponent implements OnInit, OnDestroy { private static LOADTIME_TOO_LONG: number = 30000; downloadSpeed: number; @@ -26,11 +26,12 @@ export class VideoWatchComponent implements OnInit, CanDeactivate { video: Video; private errorTimer: NodeJS.Timer; + private sub: any; private torrentInfosInterval: NodeJS.Timer; constructor( private elementRef: ElementRef, - private routeSegment: RouteSegment, + private route: ActivatedRoute, private videoService: VideoService, private webTorrentService: WebTorrentService ) {} @@ -73,22 +74,25 @@ export class VideoWatchComponent implements OnInit, CanDeactivate { }); } - ngOnInit() { - let id = this.routeSegment.getParam('id'); - this.videoService.getVideo(id).subscribe( - video => { - this.video = video; - this.loadVideo(); - }, - error => alert(error) - ); - } - - routerCanDeactivate() { + ngOnDestroy() { console.log('Removing video from webtorrent.'); clearInterval(this.torrentInfosInterval); this.webTorrentService.remove(this.video.magnetUri); - return Promise.resolve(true); + + this.sub.unsubscribe(); + } + + ngOnInit() { + this.sub = this.route.params.subscribe(routeParams => { + let id = routeParams['id']; + this.videoService.getVideo(id).subscribe( + video => { + this.video = video; + this.loadVideo(); + }, + error => alert(error) + ); + }); } private loadTooLong() { -- cgit v1.2.3