Skip to content

Commit 2857b73

Browse files
authored
refactor(youtube-player): switch to inject function (#29775)
Reworks the `youtube-player` to use the `inject` function instead of constructor-based injection.
1 parent 7c9bf99 commit 2857b73

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/youtube-player/youtube-player.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
Output,
2020
ViewChild,
2121
ViewEncapsulation,
22-
Inject,
2322
PLATFORM_ID,
2423
OnChanges,
2524
SimpleChanges,
@@ -131,19 +130,21 @@ enum PlayerState {
131130
`,
132131
})
133132
export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
134-
/** Whether we're currently rendering inside a browser. */
135-
private readonly _isBrowser: boolean;
133+
private _ngZone = inject(NgZone);
134+
private readonly _nonce = inject(CSP_NONCE, {optional: true});
135+
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
136136
private _player: YT.Player | undefined;
137137
private _pendingPlayer: YT.Player | undefined;
138138
private _existingApiReadyCallback: (() => void) | undefined;
139139
private _pendingPlayerState: PendingPlayerState | undefined;
140140
private readonly _destroyed = new Subject<void>();
141141
private readonly _playerChanges = new BehaviorSubject<YT.Player | undefined>(undefined);
142-
private readonly _nonce = inject(CSP_NONCE, {optional: true});
143-
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
144142
protected _isLoading = false;
145143
protected _hasPlaceholder = true;
146144

145+
/** Whether we're currently rendering inside a browser. */
146+
private readonly _isBrowser: boolean;
147+
147148
/** YouTube Video ID to view */
148149
@Input()
149150
videoId: string | undefined;
@@ -241,10 +242,10 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
241242
@ViewChild('youtubeContainer', {static: true})
242243
youtubeContainer: ElementRef<HTMLElement>;
243244

244-
constructor(
245-
private _ngZone: NgZone,
246-
@Inject(PLATFORM_ID) platformId: Object,
247-
) {
245+
constructor(...args: unknown[]);
246+
247+
constructor() {
248+
const platformId = inject<Object>(PLATFORM_ID);
248249
const config = inject(YOUTUBE_PLAYER_CONFIG, {optional: true});
249250
this.loadApi = config?.loadApi ?? true;
250251
this.disablePlaceholder = !!config?.disablePlaceholder;

tools/public_api_guard/youtube-player/youtube-player.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { AfterViewInit } from '@angular/core';
1010
import { ElementRef } from '@angular/core';
1111
import * as i0 from '@angular/core';
1212
import { InjectionToken } from '@angular/core';
13-
import { NgZone } from '@angular/core';
1413
import { Observable } from 'rxjs';
1514
import { OnChanges } from '@angular/core';
1615
import { OnDestroy } from '@angular/core';
@@ -24,7 +23,7 @@ export const YOUTUBE_PLAYER_CONFIG: InjectionToken<YouTubePlayerConfig>;
2423

2524
// @public
2625
export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
27-
constructor(_ngZone: NgZone, platformId: Object);
26+
constructor(...args: unknown[]);
2827
// (undocumented)
2928
readonly apiChange: Observable<YT.PlayerEvent>;
3029
disableCookies: boolean;

0 commit comments

Comments
 (0)