Skip to content

Commit 4f8a408

Browse files
committed
feat(challenge 22): refactor the code to use the router input strategy
1 parent 543770b commit 4f8a408

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ApplicationConfig } from '@angular/core';
2-
import { provideRouter } from '@angular/router';
2+
import { provideRouter, withComponentInputBinding } from '@angular/router';
33
import { appRoutes } from './app.routes';
44

55
export const appConfig: ApplicationConfig = {
6-
providers: [provideRouter(appRoutes)],
6+
providers: [provideRouter(appRoutes, withComponentInputBinding())],
77
};
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
import { AsyncPipe } from '@angular/common';
2-
import { Component, inject } from '@angular/core';
3-
import { ActivatedRoute } from '@angular/router';
4-
import { map } from 'rxjs';
1+
import { Component, input } from '@angular/core';
52

63
@Component({
74
selector: 'app-subscription',
8-
imports: [AsyncPipe],
5+
imports: [],
96
template: `
10-
<div>TestId: {{ testId$ | async }}</div>
11-
<div>Permission: {{ permission$ | async }}</div>
12-
<div>User: {{ user$ | async }}</div>
7+
<div>TestId: {{ testId() }}</div>
8+
<div>Permission: {{ permission() }}</div>
9+
<div>User: {{ user() }}</div>
1310
`,
1411
})
1512
export default class TestComponent {
16-
private activatedRoute = inject(ActivatedRoute);
17-
18-
testId$ = this.activatedRoute.params.pipe(map((p) => p['testId']));
19-
permission$ = this.activatedRoute.data.pipe(map((d) => d['permission']));
20-
user$ = this.activatedRoute.queryParams.pipe(map((q) => q['user']));
13+
testId = input<string>();
14+
user = input<string>();
15+
permission = input<string>();
2116
}

0 commit comments

Comments
 (0)