Skip to content

Commit 35dc3ec

Browse files
MeAkibthePunderWoman
authored andcommitted
refactor(common): update examples to align with Angular best practices
Updated examples to use the standalone component approach and the latest (cherry picked from commit c7affdf)
1 parent cc1ec09 commit 35dc3ec

File tree

7 files changed

+28
-37
lines changed

7 files changed

+28
-37
lines changed

packages/examples/router/activated-route/module.ts renamed to packages/examples/router/activated-route/activated_route_component.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88
// #docregion activated-route
9-
import {Component, NgModule} from '@angular/core';
9+
import {Component} from '@angular/core';
1010
// #enddocregion activated-route
11-
import {BrowserModule} from '@angular/platform-browser';
1211
// #docregion activated-route
13-
import {ActivatedRoute, RouterModule} from '@angular/router';
12+
import {ActivatedRoute} from '@angular/router';
1413
import {Observable} from 'rxjs';
1514
import {map} from 'rxjs/operators';
1615
// #enddocregion activated-route
@@ -21,7 +20,6 @@ import {map} from 'rxjs/operators';
2120
// #enddocregion activated-route
2221
selector: 'example-app',
2322
template: '...',
24-
standalone: false,
2523
// #docregion activated-route
2624
})
2725
export class ActivatedRouteComponent {
@@ -33,10 +31,3 @@ export class ActivatedRouteComponent {
3331
}
3432
}
3533
// #enddocregion activated-route
36-
37-
@NgModule({
38-
imports: [BrowserModule, RouterModule.forRoot([])],
39-
declarations: [ActivatedRouteComponent],
40-
bootstrap: [ActivatedRouteComponent],
41-
})
42-
export class AppModule {}

packages/examples/router/activated-route/main.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
import 'zone.js';
1010

11-
import {platformBrowser} from '@angular/platform-browser';
11+
import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser';
12+
import {ApplicationConfig, provideZoneChangeDetection} from '@angular/core';
13+
import {provideRouter} from '@angular/router';
14+
import {ActivatedRouteComponent} from './activated_route_component';
1215

13-
import {AppModule} from './module';
16+
const appConfig: ApplicationConfig = {
17+
providers: [provideRouter([]), provideZoneChangeDetection(), provideProtractorTestingSupport()],
18+
};
1419

15-
platformBrowser().bootstrapModule(AppModule);
20+
bootstrapApplication(ActivatedRouteComponent, appConfig).catch((err) => console.error(err));

packages/examples/router/route_functional_guards.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
ActivatedRouteSnapshot,
1414
CanActivateChildFn,
1515
CanActivateFn,
16-
CanDeactivateFn,
1716
CanMatchFn,
1817
provideRouter,
1918
ResolveFn,
@@ -24,13 +23,11 @@ import {
2423

2524
@Component({
2625
template: '',
27-
standalone: false,
2826
})
2927
export class App {}
3028

3129
@Component({
3230
template: '',
33-
standalone: false,
3431
})
3532
export class TeamComponent {}
3633

@@ -95,7 +92,6 @@ bootstrapApplication(App, {
9592
// #docregion CanDeactivateFn
9693
@Component({
9794
template: '',
98-
standalone: false,
9995
})
10096
export class UserComponent {
10197
hasUnsavedChanges = true;
@@ -135,7 +131,6 @@ bootstrapApplication(App, {
135131
// #docregion ResolveDataUse
136132
@Component({
137133
template: '',
138-
standalone: false,
139134
})
140135
export class HeroDetailComponent {
141136
constructor(private activatedRoute: ActivatedRoute) {}

packages/examples/service-worker/push/main.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@
88

99
import 'zone.js';
1010

11-
import {platformBrowser} from '@angular/platform-browser';
11+
import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser';
12+
import {AppComponent} from './service_worker_component';
13+
import {ApplicationConfig, importProvidersFrom, provideZoneChangeDetection} from '@angular/core';
14+
import {ServiceWorkerModule} from '@angular/service-worker';
1215

13-
import {AppModule} from './module';
16+
const appConfig: ApplicationConfig = {
17+
providers: [
18+
provideZoneChangeDetection(),
19+
provideProtractorTestingSupport(),
20+
importProvidersFrom(ServiceWorkerModule.register('ngsw-worker.js')),
21+
],
22+
};
1423

15-
platformBrowser().bootstrapModule(AppModule);
24+
bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));

packages/examples/service-worker/push/module.ts renamed to packages/examples/service-worker/push/service_worker_component.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88
// tslint:disable: no-duplicate-imports
9-
import {Component, NgModule} from '@angular/core';
10-
import {BrowserModule} from '@angular/platform-browser';
11-
import {ServiceWorkerModule} from '@angular/service-worker';
9+
import {Component} from '@angular/core';
10+
1211
// #docregion inject-sw-push
1312
import {SwPush} from '@angular/service-worker';
1413
// #enddocregion inject-sw-push
@@ -19,7 +18,6 @@ const PUBLIC_VAPID_KEY_OF_SERVER = '...';
1918
@Component({
2019
selector: 'example-app',
2120
template: 'SW enabled: {{ swPush.isEnabled }}',
22-
standalone: false,
2321
})
2422
// #docregion inject-sw-push
2523
export class AppComponent {
@@ -49,10 +47,3 @@ export class AppComponent {
4947
// #docregion inject-sw-push
5048
}
5149
// #enddocregion inject-sw-push
52-
53-
@NgModule({
54-
bootstrap: [AppComponent],
55-
declarations: [AppComponent],
56-
imports: [BrowserModule, ServiceWorkerModule.register('ngsw-worker.js')],
57-
})
58-
export class AppModule {}

packages/router/src/router_state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function createEmptyStateSnapshot(rootComponent: Type<any> | null): Route
115115
* on shallow equality. For example, changing deeply nested properties in resolved `data` will not
116116
* cause the `ActivatedRoute.data` `Observable` to emit a new value.
117117
*
118-
* {@example router/activated-route/module.ts region="activated-route"}
118+
* {@example router/activated-route/activated_route_component.ts region="activated-route"}
119119
*
120120
* @see [Getting route information](guide/routing/common-router-tasks#getting-route-information)
121121
*

packages/service-worker/src/push.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import {ERR_SW_NOT_SUPPORTED, NgswCommChannel, PushEvent} from './low_level';
2424
* You can inject a `SwPush` instance into any component or service
2525
* as a dependency.
2626
*
27-
* <code-example path="service-worker/push/module.ts" region="inject-sw-push"
27+
* <code-example path="service-worker/push/service_worker_component.ts" region="inject-sw-push"
2828
* header="app.component.ts"></code-example>
2929
*
3030
* To subscribe, call `SwPush.requestSubscription()`, which asks the user for permission.
3131
* The call returns a `Promise` with a new
3232
* [`PushSubscription`](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
3333
* instance.
3434
*
35-
* <code-example path="service-worker/push/module.ts" region="subscribe-to-push"
35+
* <code-example path="service-worker/push/service_worker_component.ts" region="subscribe-to-push"
3636
* header="app.component.ts"></code-example>
3737
*
3838
* A request is rejected if the user denies permission, or if the browser
@@ -78,7 +78,7 @@ import {ERR_SW_NOT_SUPPORTED, NgswCommChannel, PushEvent} from './low_level';
7878
* An application can subscribe to `SwPush.notificationClicks` observable to be notified when a user
7979
* clicks on a notification. For example:
8080
*
81-
* <code-example path="service-worker/push/module.ts" region="subscribe-to-notification-clicks"
81+
* <code-example path="service-worker/push/service_worker_component.ts" region="subscribe-to-notification-clicks"
8282
* header="app.component.ts"></code-example>
8383
*
8484
* You can read more on handling notification clicks in the [Service worker notifications

0 commit comments

Comments
 (0)