Skip to content

Commit dd7b869

Browse files
authored
build: completely switch dev app to standalone components (#24895)
Replaces all of the remaining `@NgModule` usages in the dev app with standalone components.
1 parent f76103d commit dd7b869

12 files changed

+66
-106
lines changed

src/dev-app/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ ng_module(
1010
srcs = [
1111
"dev-app.ts",
1212
"main.ts",
13-
"main-module.ts",
1413
"routes.ts",
1514
],
1615
deps = [

src/dev-app/dev-app.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
*/
88

99
import {Component, ViewEncapsulation} from '@angular/core';
10+
import {RouterModule} from '@angular/router';
11+
import {DevAppLayout} from './dev-app/dev-app-layout';
1012

1113
/** Root component for the dev-app demos. */
1214
@Component({
1315
selector: 'dev-app',
1416
template: '<dev-app-layout><router-outlet></router-outlet></dev-app-layout>',
1517
encapsulation: ViewEncapsulation.None,
18+
standalone: true,
19+
imports: [DevAppLayout, RouterModule],
1620
})
17-
export class DevAppComponent {}
21+
export class DevApp {}

src/dev-app/dev-app/dev-app-404.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88

99
import {Component} from '@angular/core';
10+
import {MatButtonModule} from '@angular/material/button';
11+
import {RouterModule} from '@angular/router';
1012

1113
@Component({
1214
template: `
@@ -15,5 +17,7 @@ import {Component} from '@angular/core';
1517
<a mat-raised-button routerLink="/">Go back to the home page</a>
1618
`,
1719
host: {'class': 'mat-typography'},
20+
standalone: true,
21+
imports: [MatButtonModule, RouterModule],
1822
})
1923
export class DevApp404 {}

src/dev-app/dev-app/dev-app-home.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ import {Component} from '@angular/core';
1414
<p>Welcome to the development demos for Angular Material!</p>
1515
<p>Open the sidenav to select a demo.</p>
1616
`,
17+
standalone: true,
1718
})
1819
export class DevAppHome {}

src/dev-app/dev-app/dev-app-layout.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import {ChangeDetectorRef, Component, ElementRef, Inject, ViewEncapsulation} fro
1111

1212
import {DevAppDirectionality} from './dev-app-directionality';
1313
import {DevAppRippleOptions} from './ripple-options';
14-
import {DOCUMENT} from '@angular/common';
14+
import {CommonModule, DOCUMENT} from '@angular/common';
15+
import {MatSidenavModule} from '@angular/material/sidenav';
16+
import {MatListModule} from '@angular/material/list';
17+
import {MatButtonModule} from '@angular/material/button';
18+
import {RouterModule} from '@angular/router';
19+
import {MatIconModule} from '@angular/material/icon';
20+
import {MatToolbarModule} from '@angular/material/toolbar';
1521

1622
const isDarkThemeKey = 'ANGULAR_COMPONENTS_DEV_APP_DARK_THEME';
1723

@@ -23,6 +29,16 @@ export const ANIMATIONS_STORAGE_KEY = 'ANGULAR_COMPONENTS_ANIMATIONS_DISABLED';
2329
templateUrl: 'dev-app-layout.html',
2430
styleUrls: ['dev-app-layout.css'],
2531
encapsulation: ViewEncapsulation.None,
32+
standalone: true,
33+
imports: [
34+
CommonModule,
35+
MatButtonModule,
36+
MatIconModule,
37+
MatListModule,
38+
MatSidenavModule,
39+
MatToolbarModule,
40+
RouterModule,
41+
],
2642
})
2743
export class DevAppLayout {
2844
readonly darkThemeClass = 'demo-unicorn-dark-theme';

src/dev-app/dev-app/dev-app-module.ts

-35
This file was deleted.

src/dev-app/example/example-list.ts

+5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
*/
88

99
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {CommonModule} from '@angular/common';
1011
import {EXAMPLE_COMPONENTS} from '@angular/components-examples';
1112
import {Component, Input} from '@angular/core';
13+
import {MatExpansionModule} from '@angular/material/expansion';
14+
import {Example} from './example';
1215

1316
/** Displays a set of components-examples in a mat-accordion. */
1417
@Component({
1518
selector: 'material-example-list',
19+
standalone: true,
20+
imports: [CommonModule, MatExpansionModule, Example],
1621
template: `
1722
<mat-accordion multi>
1823
<mat-expansion-panel *ngFor="let id of ids" [expanded]="expandAll">

src/dev-app/example/example-module.ts

-21
This file was deleted.

src/dev-app/example/example.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {CommonModule} from '@angular/common';
1011
import {EXAMPLE_COMPONENTS} from '@angular/components-examples';
1112
import {loadExample} from '@angular/components-examples/private';
1213
import {
@@ -20,6 +21,8 @@ import {
2021

2122
@Component({
2223
selector: 'material-example',
24+
standalone: true,
25+
imports: [CommonModule],
2326
template: `
2427
<div class="label" *ngIf="showLabel">
2528
<span class="title"> {{title}} </span>

src/dev-app/examples-page/examples-page.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import {Component} from '@angular/core';
1010
import {EXAMPLE_COMPONENTS} from '@angular/components-examples';
11-
import {ExampleModule} from '../example/example-module';
11+
import {ExampleList} from '../example/example-list';
1212

1313
/** Renders all material examples listed in the generated EXAMPLE_COMPONENTS. */
1414
@Component({
1515
template: `<material-example-list [ids]="examples"></material-example-list>`,
1616
standalone: true,
17-
imports: [ExampleModule],
17+
imports: [ExampleList],
1818
})
1919
export class ExamplesPage {
2020
examples = Object.keys(EXAMPLE_COMPONENTS);

src/dev-app/main-module.ts

-42
This file was deleted.

src/dev-app/main.ts

+29-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,33 @@
99
// Load `$localize` for examples using it.
1010
import '@angular/localize/init';
1111

12-
import {platformBrowser} from '@angular/platform-browser';
13-
import {MainModule} from './main-module';
12+
import {importProvidersFrom} from '@angular/core';
13+
import {HttpClientModule} from '@angular/common/http';
14+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
15+
import {RouterModule} from '@angular/router';
16+
import {bootstrapApplication} from '@angular/platform-browser';
1417

15-
platformBrowser().bootstrapModule(MainModule);
18+
import {MAT_RIPPLE_GLOBAL_OPTIONS} from '@angular/material/core';
19+
import {Directionality} from '@angular/cdk/bidi';
20+
import {OverlayContainer, FullscreenOverlayContainer} from '@angular/cdk/overlay';
21+
22+
import {DevApp} from './dev-app';
23+
import {DevAppDirectionality} from './dev-app/dev-app-directionality';
24+
import {DevAppRippleOptions} from './dev-app/ripple-options';
25+
import {ANIMATIONS_STORAGE_KEY} from './dev-app/dev-app-layout';
26+
import {DEV_APP_ROUTES} from './routes';
27+
28+
bootstrapApplication(DevApp, {
29+
providers: [
30+
importProvidersFrom(
31+
BrowserAnimationsModule.withConfig({
32+
disableAnimations: localStorage.getItem(ANIMATIONS_STORAGE_KEY) === 'true',
33+
}),
34+
RouterModule.forRoot(DEV_APP_ROUTES),
35+
HttpClientModule,
36+
),
37+
{provide: OverlayContainer, useClass: FullscreenOverlayContainer},
38+
{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useExisting: DevAppRippleOptions},
39+
{provide: Directionality, useClass: DevAppDirectionality},
40+
],
41+
});

0 commit comments

Comments
 (0)