Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component } from '@angular/core';
import { RouterLink, RouterOutlet } from '@angular/router';

@Component({
selector: 'app-root',
imports: [RouterOutlet, RouterLink],
template: `
<div class="flex gap-2">
<button
Expand All @@ -25,6 +27,5 @@ import { Component } from '@angular/core';
host: {
class: 'flex flex-col p-4 gap-3',
},
standalone: false,
})
export class AppComponent {}
12 changes: 12 additions & 0 deletions apps/angular/31-module-to-standalone/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { provideToken } from '@angular-challenges/module-to-standalone/core/providers';
import { appRoutes } from '@angular-challenges/module-to-standalone/shell';
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';

export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection(),
provideRouter(appRoutes),
provideToken('main-shell-token'),
],
};
11 changes: 0 additions & 11 deletions apps/angular/31-module-to-standalone/src/app/app.module.ts

This file was deleted.

14 changes: 6 additions & 8 deletions apps/angular/31-module-to-standalone/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { provideZoneChangeDetection } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';

platformBrowserDynamic()
.bootstrapModule(AppModule, {
applicationProviders: [provideZoneChangeDetection()],
})
.catch((err) => console.error(err));
bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err),
);
2 changes: 1 addition & 1 deletion libs/module-to-standalone/admin/feature/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/admin-feature.module';
export { default } from './lib/admin-feature.routes';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Route } from '@angular/router';

const adminFeatureRoutes: Route[] = [
{
path: '',
loadComponent: () => import('./dashboard/dashboard.component'),
},
{
path: 'create-user',
loadComponent: () => import('./create-user/create-user.component'),
},
];

export default adminFeatureRoutes;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Component } from '@angular/core';

@Component({
selector: 'lib-create-user',
Expand All @@ -12,14 +11,5 @@ import { RouterModule } from '@angular/router';
Back
</button>
`,
standalone: false,
})
export class CreateUserComponent {}

@NgModule({
imports: [
RouterModule.forChild([{ path: '', component: CreateUserComponent }]),
],
declarations: [CreateUserComponent],
})
export class CreateUserModule {}
export default class CreateUserComponent {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Component } from '@angular/core';

@Component({
selector: 'lib-dashboard',
Expand All @@ -12,14 +11,5 @@ import { RouterModule } from '@angular/router';
Create User
</button>
`,
standalone: false,
})
export class DashboardComponent {}

@NgModule({
imports: [
RouterModule.forChild([{ path: '', component: DashboardComponent }]),
],
declarations: [DashboardComponent],
})
export class DashboardModule {}
export default class DashboardComponent {}
29 changes: 12 additions & 17 deletions libs/module-to-standalone/admin/shared/src/lib/authorized.guard.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { CanActivate, Router, UrlTree } from '@angular/router';
import { CanActivateFn, Router } from '@angular/router';

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

@Injectable({
providedIn: 'root',
})
export class IsAuthorizedGuard implements CanActivate {
private authorizationService = inject(AuthorizationService);
private router = inject(Router);
export const isAuthorizedGuard: CanActivateFn = () => {
const authorizationService = inject(AuthorizationService);
const router = inject(Router);

canActivate(): Observable<boolean | UrlTree> {
return this.authorizationService.isAuthorized$.pipe(
map((isAuthorized) =>
isAuthorized ? true : this.router.createUrlTree(['forbidden']),
),
);
}
}
return authorizationService.isAuthorized$.pipe(
map((isAuthorized) => {
return isAuthorized ? true : router.createUrlTree(['forbidden']);
}),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
makeEnvironmentProviders,
} from '@angular/core';

export const TOKEN = new InjectionToken<string[]>('token');
export const TOKEN = new InjectionToken<string>('token');

export const provideToken = (token: string): EnvironmentProviders => {
return makeEnvironmentProviders([
Expand Down
2 changes: 1 addition & 1 deletion libs/module-to-standalone/forbidden/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/forbidden.module';
export { default } from './lib/forbidden.component';
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Component } from '@angular/core';

@Component({
selector: 'lib-home',
selector: 'lib-forbidden',
template: `
Forbidden component
`,
standalone: false,
})
export class ForbiddenComponent {}
export default class ForbiddenComponent {}
13 changes: 0 additions & 13 deletions libs/module-to-standalone/forbidden/src/lib/forbidden.module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/module-to-standalone/home/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/home.module';
export { default } from './lib/home.component';
9 changes: 5 additions & 4 deletions libs/module-to-standalone/home/src/lib/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { TOKEN } from '@angular-challenges/module-to-standalone/core/providers';
import { AuthorizationService } from '@angular-challenges/module-to-standalone/core/service';
import { CommonModule } from '@angular/common';
import { Component, inject } from '@angular/core';

@Component({
selector: 'lib-home',
imports: [CommonModule],
template: `
Home component

<section class="flex items-center gap-5">
Authorization :
<button class="border p-2 " (click)="authorizeService.authorize()">
<button class="border p-2" (click)="authorizeService.authorize()">
Authorize
</button>
<button class="border p-2 " (click)="authorizeService.forbid()">
<button class="border p-2" (click)="authorizeService.forbid()">
Forbid
</button>
(isAuthorized: {{ authorizeService.isAuthorized$ | async }})
</section>

<section>LoadedToken {{ token }}</section>
`,
standalone: false,
})
export class HomeComponent {
export default class HomeComponent {
public authorizeService = inject(AuthorizationService);
public token = inject(TOKEN);
}
13 changes: 0 additions & 13 deletions libs/module-to-standalone/home/src/lib/home.module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/module-to-standalone/shell/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/main-shell.module';
export * from './lib/main-shell.routes';
11 changes: 0 additions & 11 deletions libs/module-to-standalone/shell/src/lib/main-shell.module.ts

This file was deleted.

24 changes: 8 additions & 16 deletions libs/module-to-standalone/shell/src/lib/main-shell.routes.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
import { IsAuthorizedGuard } from '@angular-challenges/module-to-standalone/admin/shared';
import { isAuthorizedGuard } from '@angular-challenges/module-to-standalone/admin/shared';
import { Route } from '@angular/router';

export const appRoutes: Route[] = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{
path: 'home',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/home').then(
(m) => m.ModuleToStandaloneHomeModule,
),
loadComponent: () =>
import('@angular-challenges/module-to-standalone/home'),
},
{
path: 'admin',
canActivate: [IsAuthorizedGuard],
canActivate: [isAuthorizedGuard],
loadChildren: () =>
import('@angular-challenges/module-to-standalone/admin/feature').then(
(m) => m.AdminFeatureModule,
),
import('@angular-challenges/module-to-standalone/admin/feature'),
},
{
path: 'user',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/user/shell').then(
(m) => m.UserShellModule,
),
import('@angular-challenges/module-to-standalone/user/shell'),
},

{
path: 'forbidden',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/forbidden').then(
(m) => m.ForbiddenModule,
),
loadComponent: () =>
import('@angular-challenges/module-to-standalone/forbidden'),
},
];
2 changes: 1 addition & 1 deletion libs/module-to-standalone/user/contact/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/contact-feature.module';
export { default } from './lib/contact-feature.routes';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Route } from '@angular/router';

const contactFeatureRoutes: Route[] = [
{
path: '',
loadComponent: () => import('./dashboard/dashboard.component'),
},
{
path: 'create-contact',
loadComponent: () => import('./create-contact/create-contact.component'),
},
];

export default contactFeatureRoutes;
Loading
Loading