Skip to content

refactor(youtube-player): switch to inject function #29775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/youtube-player/youtube-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
Output,
ViewChild,
ViewEncapsulation,
Inject,
PLATFORM_ID,
OnChanges,
SimpleChanges,
Expand Down Expand Up @@ -131,19 +130,21 @@ enum PlayerState {
`,
})
export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
/** Whether we're currently rendering inside a browser. */
private readonly _isBrowser: boolean;
private _ngZone = inject(NgZone);
private readonly _nonce = inject(CSP_NONCE, {optional: true});
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
private _player: YT.Player | undefined;
private _pendingPlayer: YT.Player | undefined;
private _existingApiReadyCallback: (() => void) | undefined;
private _pendingPlayerState: PendingPlayerState | undefined;
private readonly _destroyed = new Subject<void>();
private readonly _playerChanges = new BehaviorSubject<YT.Player | undefined>(undefined);
private readonly _nonce = inject(CSP_NONCE, {optional: true});
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
protected _isLoading = false;
protected _hasPlaceholder = true;

/** Whether we're currently rendering inside a browser. */
private readonly _isBrowser: boolean;

/** YouTube Video ID to view */
@Input()
videoId: string | undefined;
Expand Down Expand Up @@ -241,10 +242,10 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
@ViewChild('youtubeContainer', {static: true})
youtubeContainer: ElementRef<HTMLElement>;

constructor(
private _ngZone: NgZone,
@Inject(PLATFORM_ID) platformId: Object,
) {
constructor(...args: unknown[]);

constructor() {
const platformId = inject<Object>(PLATFORM_ID);
const config = inject(YOUTUBE_PLAYER_CONFIG, {optional: true});
this.loadApi = config?.loadApi ?? true;
this.disablePlaceholder = !!config?.disablePlaceholder;
Expand Down
3 changes: 1 addition & 2 deletions tools/public_api_guard/youtube-player/youtube-player.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AfterViewInit } from '@angular/core';
import { ElementRef } from '@angular/core';
import * as i0 from '@angular/core';
import { InjectionToken } from '@angular/core';
import { NgZone } from '@angular/core';
import { Observable } from 'rxjs';
import { OnChanges } from '@angular/core';
import { OnDestroy } from '@angular/core';
Expand All @@ -24,7 +23,7 @@ export const YOUTUBE_PLAYER_CONFIG: InjectionToken<YouTubePlayerConfig>;

// @public
export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
constructor(_ngZone: NgZone, platformId: Object);
constructor(...args: unknown[]);
// (undocumented)
readonly apiChange: Observable<YT.PlayerEvent>;
disableCookies: boolean;
Expand Down
Loading