|
1 | | -import { Component, inject, input } from '@angular/core'; |
| 1 | +import { Component, computed, inject, input } from '@angular/core'; |
2 | 2 | import { toSignal } from '@angular/core/rxjs-interop'; |
3 | 3 | import { RouterLink, RouterLinkActive } from '@angular/router'; |
4 | 4 | import { FakeServiceService } from './fake.service'; |
@@ -38,25 +38,19 @@ export class NavigationComponent { |
38 | 38 | @Component({ |
39 | 39 | imports: [NavigationComponent], |
40 | 40 | template: ` |
41 | | - @if (info() !== null) { |
42 | | - <app-nav [menus]="getMenu(info()!)" /> |
43 | | - } @else { |
44 | | - <app-nav [menus]="getMenu('')" /> |
45 | | - } |
| 41 | + <app-nav [menus]="menus()" /> |
46 | 42 | `, |
47 | 43 | host: {}, |
48 | 44 | }) |
49 | 45 | export class MainNavigationComponent { |
50 | 46 | private fakeBackend = inject(FakeServiceService); |
51 | 47 |
|
52 | 48 | readonly info = toSignal(this.fakeBackend.getInfoFromBackend(), { |
53 | | - initialValue: null, |
| 49 | + initialValue: '', |
54 | 50 | }); |
55 | 51 |
|
56 | | - getMenu(prop: string) { |
57 | | - return [ |
58 | | - { path: '/foo', name: `Foo ${prop}` }, |
59 | | - { path: '/bar', name: `Bar ${prop}` }, |
60 | | - ]; |
61 | | - } |
| 52 | + readonly menus = computed<MenuItem[]>(() => [ |
| 53 | + { path: '/foo', name: `Foo ${this.info()}` }, |
| 54 | + { path: '/bar', name: `Bar ${this.info()}` }, |
| 55 | + ]); |
62 | 56 | } |
0 commit comments