Skip to content

Commit 696161a

Browse files
committed
refactor(material-angular-io): switch to inject function
Runs the inject migration over the docs site to make it consistent with the rest of the repo.
1 parent 57fbe7f commit 696161a

File tree

28 files changed

+158
-135
lines changed

28 files changed

+158
-135
lines changed

material.angular.io/scenes/src/app/scene-viewer/scene-viewer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ViewContainerRef,
77
ViewEncapsulation,
88
viewChild,
9+
inject,
910
} from '@angular/core';
1011
import {ActivatedRoute} from '@angular/router';
1112
import {DomSanitizer, SafeStyle} from '@angular/platform-browser';
@@ -18,6 +19,9 @@ import {DomSanitizer, SafeStyle} from '@angular/platform-browser';
1819
standalone: true,
1920
})
2021
export class SceneViewer implements OnInit {
22+
private route = inject(ActivatedRoute);
23+
private sanitizer = inject(DomSanitizer);
24+
2125
@HostBinding('style.filter') filter: SafeStyle | undefined;
2226

2327
/**
@@ -45,10 +49,7 @@ export class SceneViewer implements OnInit {
4549

4650
readonly scene = viewChild.required('scene', {read: ViewContainerRef});
4751

48-
constructor(
49-
private route: ActivatedRoute,
50-
private sanitizer: DomSanitizer,
51-
) {
52+
constructor() {
5253
this.hueRotation = this.route.snapshot.data['hueRotate'];
5354
this.component = this.route.snapshot.data['scene'];
5455
this.scale = this.route.snapshot.data['scale'];

material.angular.io/scenes/src/app/scenes/bottom-sheet/bottom-sheet-scene.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AfterViewInit, Component, ViewEncapsulation} from '@angular/core';
1+
import {AfterViewInit, Component, ViewEncapsulation, inject} from '@angular/core';
22
import {MatBottomSheet} from '@angular/material/bottom-sheet';
33
import {MatIconModule} from '@angular/material/icon';
44
import {MatListModule} from '@angular/material/list';
@@ -11,7 +11,7 @@ import {MatListModule} from '@angular/material/list';
1111
standalone: true,
1212
})
1313
export class BottomSheetScene implements AfterViewInit {
14-
constructor(private _bottomSheet: MatBottomSheet) {}
14+
private _bottomSheet = inject(MatBottomSheet);
1515

1616
ngAfterViewInit(): void {
1717
this._bottomSheet.open(SampleBottomSheet);

material.angular.io/scenes/src/app/scenes/dialog/dialog-scene.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, ViewEncapsulation} from '@angular/core';
1+
import {Component, ViewEncapsulation, inject} from '@angular/core';
22
import {MatButtonModule} from '@angular/material/button';
33
import {MatDialog, MatDialogModule} from '@angular/material/dialog';
44

@@ -9,7 +9,9 @@ import {MatDialog, MatDialogModule} from '@angular/material/dialog';
99
standalone: true,
1010
})
1111
export class DialogScene {
12-
constructor(public dialog: MatDialog) {
12+
dialog = inject(MatDialog);
13+
14+
constructor() {
1315
this.openDialog();
1416
}
1517

material.angular.io/scenes/src/app/scenes/snack-bar/snack-bar-scene.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, ViewEncapsulation} from '@angular/core';
1+
import {Component, ViewEncapsulation, inject} from '@angular/core';
22
import {MatSnackBar} from '@angular/material/snack-bar';
33

44
@Component({
@@ -9,7 +9,9 @@ import {MatSnackBar} from '@angular/material/snack-bar';
99
standalone: true,
1010
})
1111
export class SnackBarScene {
12-
constructor(snackbar: MatSnackBar) {
12+
constructor() {
13+
const snackbar = inject(MatSnackBar);
14+
1315
snackbar.open('Message archived', 'Undo');
1416
}
1517
}

material.angular.io/src/app/material-docs-app.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnDestroy, ViewEncapsulation} from '@angular/core';
1+
import {Component, OnDestroy, ViewEncapsulation, inject} from '@angular/core';
22

33
import {AnalyticsService} from './shared/analytics/analytics';
44
import {NavigationFocusService} from './shared/navigation-focus/navigation-focus.service';
@@ -23,7 +23,10 @@ import {CookiePopup} from './shared/cookie-popup/cookie-popup';
2323
export class MaterialDocsApp implements OnDestroy {
2424
private subscriptions = new Subscription();
2525

26-
constructor(analytics: AnalyticsService, navigationFocusService: NavigationFocusService) {
26+
constructor() {
27+
const analytics = inject(AnalyticsService);
28+
const navigationFocusService = inject(NavigationFocusService);
29+
2730
this.subscriptions.add(
2831
navigationFocusService.navigationEndEvents
2932
.pipe(

material.angular.io/src/app/pages/component-category-list/component-category-list.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnDestroy, OnInit} from '@angular/core';
1+
import {Component, OnDestroy, OnInit, inject} from '@angular/core';
22
import {ActivatedRoute, RouterLink} from '@angular/router';
33
import {MatRipple} from '@angular/material/core';
44
import {combineLatest, Subscription} from 'rxjs';
@@ -20,17 +20,15 @@ import {ComponentPageTitle} from '../page-title/page-title';
2020
imports: [NavigationFocus, RouterLink, MatRipple],
2121
})
2222
export class ComponentCategoryList implements OnInit, OnDestroy {
23+
readonly _docItems = inject(DocumentationItems);
24+
private _componentPageTitle = inject(ComponentPageTitle);
25+
private _route = inject(ActivatedRoute);
26+
2327
items: DocItem[] = [];
2428
section = '';
2529
routeParamSubscription: Subscription = new Subscription();
2630
_categoryListSummary: string | undefined;
2731

28-
constructor(
29-
readonly _docItems: DocumentationItems,
30-
private _componentPageTitle: ComponentPageTitle,
31-
private _route: ActivatedRoute,
32-
) {}
33-
3432
ngOnInit() {
3533
this.routeParamSubscription = combineLatest(
3634
this._route.pathFromRoot.map(route => route.params),

material.angular.io/src/app/pages/component-sidenav/component-sidenav-can-load-guard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Injectable} from '@angular/core';
1+
import {Injectable, inject} from '@angular/core';
22
import {ActivatedRouteSnapshot, Router} from '@angular/router';
33
import {SECTIONS} from '../../shared/documentation-items/documentation-items';
44

@@ -8,7 +8,7 @@ import {SECTIONS} from '../../shared/documentation-items/documentation-items';
88
*/
99
@Injectable({providedIn: 'root'})
1010
export class CanActivateComponentSidenav {
11-
constructor(private router: Router) {}
11+
private router = inject(Router);
1212

1313
canActivate(route: ActivatedRouteSnapshot) {
1414
// Searches if the section defined in the base UrlSegment is a valid section from the

material.angular.io/src/app/pages/component-sidenav/component-sidenav.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ const SMALL_WIDTH_BREAKPOINT = 959;
6868
],
6969
})
7070
export class ComponentSidenav implements OnInit, OnDestroy {
71+
docItems = inject(DocumentationItems);
72+
private _route = inject(ActivatedRoute);
73+
private _navigationFocusService = inject(NavigationFocusService);
74+
7175
readonly sidenav = viewChild(MatSidenav);
7276
params: Observable<Params>;
7377
isExtraScreenSmall: Observable<boolean>;
7478
isScreenSmall: Observable<boolean>;
7579
private _subscriptions = new Subscription();
7680

77-
constructor(
78-
public docItems: DocumentationItems,
79-
private _route: ActivatedRoute,
80-
private _navigationFocusService: NavigationFocusService,
81-
breakpoints: BreakpointObserver,
82-
) {
81+
constructor() {
82+
const breakpoints = inject(BreakpointObserver);
83+
8384
this.isExtraScreenSmall = breakpoints
8485
.observe(`(max-width: ${EXTRA_SMALL_WIDTH_BREAKPOINT}px)`)
8586
.pipe(map(breakpoint => breakpoint.matches));

material.angular.io/src/app/pages/component-viewer/component-styling.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ interface StyleOverridesData {
1919

2020
@Injectable({providedIn: 'root'})
2121
class TokenService {
22-
private _cache: Record<string, Observable<StyleOverridesData>> = {};
22+
private _http = inject(HttpClient);
2323

24-
constructor(private _http: HttpClient) {}
24+
private _cache: Record<string, Observable<StyleOverridesData>> = {};
2525

2626
getTokenData(item: DocItem): Observable<StyleOverridesData> {
2727
const url = `/docs-content/tokens/${item.packageName}/${item.id}/${item.id}.json`;

material.angular.io/src/app/pages/component-viewer/component-viewer.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ViewEncapsulation,
1010
viewChild,
1111
viewChildren,
12+
inject,
1213
} from '@angular/core';
1314
import {ActivatedRoute, Router, RouterLinkActive, RouterLink, RouterOutlet} from '@angular/router';
1415
import {combineLatest, Observable, ReplaySubject, Subject} from 'rxjs';
@@ -39,16 +40,19 @@ import {MatTabLink, MatTabNav, MatTabNavPanel} from '@angular/material/tabs';
3940
],
4041
})
4142
export class ComponentViewer implements OnDestroy {
43+
private router = inject(Router);
44+
componentPageTitle = inject(ComponentPageTitle);
45+
readonly docItems = inject(DocumentationItems);
46+
4247
componentDocItem = new ReplaySubject<DocItem>(1);
4348
sections: Set<string> = new Set(['overview', 'api']);
4449
private _destroyed = new Subject<void>();
4550

46-
constructor(
47-
route: ActivatedRoute,
48-
private router: Router,
49-
public componentPageTitle: ComponentPageTitle,
50-
readonly docItems: DocumentationItems,
51-
) {
51+
constructor() {
52+
const route = inject(ActivatedRoute);
53+
const componentPageTitle = this.componentPageTitle;
54+
const docItems = this.docItems;
55+
5256
const routeAndParentParams = [route.params];
5357
if (route.parent) {
5458
routeAndParentParams.push(route.parent.params);
@@ -101,17 +105,18 @@ export class ComponentViewer implements OnDestroy {
101105
*/
102106
@Directive()
103107
export class ComponentBaseView implements OnInit, OnDestroy {
108+
componentViewer = inject(ComponentViewer);
109+
private changeDetectorRef = inject(ChangeDetectorRef);
110+
104111
readonly tableOfContents = viewChild<TableOfContents>('toc');
105112
readonly viewers = viewChildren(DocViewer);
106113

107114
showToc: Observable<boolean>;
108115
private _destroyed = new Subject<void>();
109116

110-
constructor(
111-
public componentViewer: ComponentViewer,
112-
breakpointObserver: BreakpointObserver,
113-
private changeDetectorRef: ChangeDetectorRef,
114-
) {
117+
constructor() {
118+
const breakpointObserver = inject(BreakpointObserver);
119+
115120
this.showToc = breakpointObserver.observe('(max-width: 1200px)').pipe(
116121
map(result => {
117122
this.changeDetectorRef.detectChanges();

0 commit comments

Comments
 (0)