Skip to content

Commit

Permalink
feat(youtube-player): add feature for waiting until the API has finis…
Browse files Browse the repository at this point in the history
…hed loading (angular#16998)
  • Loading branch information
Nathan Tate authored and jelbourn committed Sep 6, 2019
1 parent f02fb47 commit 83545cf
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 209 deletions.
3 changes: 1 addition & 2 deletions src/dev-app/youtube-player/youtube-player-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ <h1>Basic Example</h1>
<mat-radio-button [value]="undefined">Unset</mat-radio-button>
</mat-radio-group>
</div>
<p *ngIf="!apiLoaded">Loading youtube api...</p>
<youtube-player *ngIf="apiLoaded" [videoId]="video && video.id"></youtube-player>
<youtube-player [videoId]="video && video.id"></youtube-player>
</section>
</div>
21 changes: 1 addition & 20 deletions src/dev-app/youtube-player/youtube-player-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ChangeDetectorRef, Component} from '@angular/core';

declare global {
interface Window {
YT: typeof YT | undefined;
onYouTubeIframeAPIReady: () => void;
}
}
import {Component} from '@angular/core';

interface Video {
id: string;
Expand Down Expand Up @@ -45,16 +38,4 @@ export class YouTubePlayerDemo {
video: Video | undefined = VIDEOS[0];
videos = VIDEOS;
apiLoaded = false;

constructor(private _ref: ChangeDetectorRef) {
if (window.YT) {
this.apiLoaded = true;
return;
}

window.onYouTubeIframeAPIReady = () => {
this.apiLoaded = true;
this._ref.detectChanges();
};
}
}
Loading

0 comments on commit 83545cf

Please sign in to comment.