File tree 4 files changed +38
-9
lines changed
4 files changed +38
-9
lines changed Original file line number Diff line number Diff line change 16
16
"@angular/material-moment-adapter" : [" ../material-moment-adapter/public-api.ts" ],
17
17
"@angular/google-maps" : [" ../google-maps" ],
18
18
"@angular/components-examples" : [" ../components-examples" ],
19
- "@angular/components-examples/*" : [" ../components-examples/*" ]
19
+ "@angular/components-examples/*" : [" ../components-examples/*" ],
20
+ "@angular/youtube-player" : [" ../youtube-player" ]
20
21
}
21
22
},
22
23
"include" : [" ./**/*.ts" ]
Original file line number Diff line number Diff line change 1
- < div >
1
+ < div #demoYouTubePlayer class =" demo-youtube-player " >
2
2
< h1 > Basic Example</ h1 >
3
3
< section >
4
4
< div class ="demo-video-selection ">
5
5
< label > Pick the video:</ label >
6
- < mat-radio-group aria-label ="Select a video " [(ngModel)] ="video ">
6
+ < mat-radio-group aria-label ="Select a video " [(ngModel)] ="selectedVideo ">
7
7
< mat-radio-button *ngFor ="let video of videos " [value] ="video ">
8
8
{{video.name}}
9
9
</ mat-radio-button >
10
10
< mat-radio-button [value] ="undefined "> Unset</ mat-radio-button >
11
11
</ mat-radio-group >
12
12
</ div >
13
- < youtube-player [videoId] ="video && video.id "> </ youtube-player >
13
+ < youtube-player [videoId] ="selectedVideo && selectedVideo.id "
14
+ [width] ="videoWidth " [height] ="videoHeight "> </ youtube-player >
14
15
</ section >
15
16
</ div >
Original file line number Diff line number Diff line change 1
1
.demo-video-selection {
2
2
margin-bottom : 20px ;
3
3
4
- mat-radio-button {
4
+ . mat-radio-button {
5
5
margin : 8px ;
6
6
}
7
7
}
Original file line number Diff line number Diff line change 6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { Component } from '@angular/core' ;
9
+ import {
10
+ AfterViewInit ,
11
+ ChangeDetectorRef ,
12
+ Component ,
13
+ ElementRef ,
14
+ OnDestroy ,
15
+ ViewChild
16
+ } from '@angular/core' ;
10
17
11
18
interface Video {
12
19
id : string ;
@@ -33,8 +40,28 @@ const VIDEOS: Video[] = [
33
40
templateUrl : 'youtube-player-demo.html' ,
34
41
styleUrls : [ 'youtube-player-demo.css' ] ,
35
42
} )
36
- export class YouTubePlayerDemo {
37
- video : Video | undefined = VIDEOS [ 0 ] ;
43
+ export class YouTubePlayerDemo implements AfterViewInit , OnDestroy {
44
+ @ViewChild ( 'demoYouTubePlayer' ) demoYouTubePlayer : ElementRef < HTMLDivElement > ;
45
+ selectedVideo : Video | undefined = VIDEOS [ 0 ] ;
38
46
videos = VIDEOS ;
39
- apiLoaded = false ;
47
+ videoWidth : number | undefined ;
48
+ videoHeight : number | undefined ;
49
+
50
+ constructor ( private _changeDetectorRef : ChangeDetectorRef ) { }
51
+
52
+ ngAfterViewInit ( ) : void {
53
+ this . onResize ( ) ;
54
+ window . addEventListener ( 'resize' , this . onResize ) ;
55
+ }
56
+
57
+ onResize = ( ) : void => {
58
+ // Automatically expand the video to fit the page up to 1200px x 720px
59
+ this . videoWidth = Math . min ( this . demoYouTubePlayer . nativeElement . clientWidth , 1200 ) ;
60
+ this . videoHeight = this . videoWidth * 0.6 ;
61
+ this . _changeDetectorRef . detectChanges ( ) ;
62
+ }
63
+
64
+ ngOnDestroy ( ) : void {
65
+ window . removeEventListener ( 'resize' , this . onResize ) ;
66
+ }
40
67
}
You can’t perform that action at this time.
0 commit comments