Skip to content

Commit 02ed0d7

Browse files
committed
refactor(test): simplify TestComponent by removing async pipes and using direct inputs
1 parent 418a2fd commit 02ed0d7

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

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 as RouterInput } 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+
@RouterInput() testId!: string;
14+
@RouterInput() permission!: string;
15+
@RouterInput() user!: string;
2116
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { provideZoneChangeDetection } from '@angular/core';
21
import { bootstrapApplication } from '@angular/platform-browser';
2+
import { provideRouter, withComponentInputBinding } from '@angular/router';
33
import { AppComponent } from './app/app.component';
4-
import { appConfig } from './app/app.config';
4+
import { appRoutes } from './app/app.routes';
55

66
bootstrapApplication(AppComponent, {
7-
...appConfig,
8-
providers: [provideZoneChangeDetection(), ...appConfig.providers],
9-
}).catch((err) => console.error(err));
7+
providers: [provideRouter(appRoutes, withComponentInputBinding())],
8+
});

0 commit comments

Comments
 (0)