Skip to content

Commit 2cecca0

Browse files
committed
feat(challenge 31): convert to standalone
1 parent 543770b commit 2cecca0

32 files changed

Lines changed: 107 additions & 242 deletions

apps/angular/31-module-to-standalone/src/app/app.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Component } from '@angular/core';
2+
import { RouterLink, RouterOutlet } from '@angular/router';
23

34
@Component({
45
selector: 'app-root',
6+
imports: [RouterOutlet, RouterLink],
57
template: `
68
<div class="flex gap-2">
79
<button
@@ -25,6 +27,5 @@ import { Component } from '@angular/core';
2527
host: {
2628
class: 'flex flex-col p-4 gap-3',
2729
},
28-
standalone: false,
2930
})
3031
export class AppComponent {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { provideToken } from '@angular-challenges/module-to-standalone/core/providers';
2+
import { appRoutes } from '@angular-challenges/module-to-standalone/shell';
3+
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
4+
import { provideRouter } from '@angular/router';
5+
6+
export const appConfig: ApplicationConfig = {
7+
providers: [
8+
provideZoneChangeDetection(),
9+
provideRouter(appRoutes),
10+
provideToken('main-shell-token'),
11+
],
12+
};

apps/angular/31-module-to-standalone/src/app/app.module.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { provideZoneChangeDetection } from '@angular/core';
2-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3-
import { AppModule } from './app/app.module';
1+
import { bootstrapApplication } from '@angular/platform-browser';
2+
import { AppComponent } from './app/app.component';
3+
import { appConfig } from './app/app.config';
44

5-
platformBrowserDynamic()
6-
.bootstrapModule(AppModule, {
7-
applicationProviders: [provideZoneChangeDetection()],
8-
})
9-
.catch((err) => console.error(err));
5+
bootstrapApplication(AppComponent, appConfig).catch((err) =>
6+
console.error(err),
7+
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './lib/admin-feature.module';
1+
export { default } from './lib/admin-feature.routes';

libs/module-to-standalone/admin/feature/src/lib/admin-feature.module.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Route } from '@angular/router';
2+
3+
const adminFeatureRoutes: Route[] = [
4+
{
5+
path: '',
6+
loadComponent: () => import('./dashboard/dashboard.component'),
7+
},
8+
{
9+
path: 'create-user',
10+
loadComponent: () => import('./create-user/create-user.component'),
11+
},
12+
];
13+
14+
export default adminFeatureRoutes;
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Component, NgModule } from '@angular/core';
2-
import { RouterModule } from '@angular/router';
1+
import { Component } from '@angular/core';
32

43
@Component({
54
selector: 'lib-create-user',
@@ -12,14 +11,5 @@ import { RouterModule } from '@angular/router';
1211
Back
1312
</button>
1413
`,
15-
standalone: false,
1614
})
17-
export class CreateUserComponent {}
18-
19-
@NgModule({
20-
imports: [
21-
RouterModule.forChild([{ path: '', component: CreateUserComponent }]),
22-
],
23-
declarations: [CreateUserComponent],
24-
})
25-
export class CreateUserModule {}
15+
export default class CreateUserComponent {}
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Component, NgModule } from '@angular/core';
2-
import { RouterModule } from '@angular/router';
1+
import { Component } from '@angular/core';
32

43
@Component({
54
selector: 'lib-dashboard',
@@ -12,14 +11,5 @@ import { RouterModule } from '@angular/router';
1211
Create User
1312
</button>
1413
`,
15-
standalone: false,
1614
})
17-
export class DashboardComponent {}
18-
19-
@NgModule({
20-
imports: [
21-
RouterModule.forChild([{ path: '', component: DashboardComponent }]),
22-
],
23-
declarations: [DashboardComponent],
24-
})
25-
export class DashboardModule {}
15+
export default class DashboardComponent {}
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
import { CanActivate, Router, UrlTree } from '@angular/router';
1+
import { CanActivateFn, Router } from '@angular/router';
22

33
import { AuthorizationService } from '@angular-challenges/module-to-standalone/core/service';
4-
import { inject, Injectable } from '@angular/core';
5-
import { map, Observable } from 'rxjs';
4+
import { inject } from '@angular/core';
5+
import { map } from 'rxjs';
66

7-
@Injectable({
8-
providedIn: 'root',
9-
})
10-
export class IsAuthorizedGuard implements CanActivate {
11-
private authorizationService = inject(AuthorizationService);
12-
private router = inject(Router);
7+
export const isAuthorizedGuard: CanActivateFn = () => {
8+
const authorizationService = inject(AuthorizationService);
9+
const router = inject(Router);
1310

14-
canActivate(): Observable<boolean | UrlTree> {
15-
return this.authorizationService.isAuthorized$.pipe(
16-
map((isAuthorized) =>
17-
isAuthorized ? true : this.router.createUrlTree(['forbidden']),
18-
),
19-
);
20-
}
21-
}
11+
return authorizationService.isAuthorized$.pipe(
12+
map((isAuthorized) => {
13+
return isAuthorized ? true : router.createUrlTree(['forbidden']);
14+
}),
15+
);
16+
};

0 commit comments

Comments
 (0)