Skip to content

Commit 14b08e9

Browse files
committed
feat(32): 32-change-detection-bug
1 parent 76e7746 commit 14b08e9

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

apps/angular/32-change-detection-bug/src/app/main-navigation.component.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, inject, input } from '@angular/core';
1+
import { Component, computed, inject, input } from '@angular/core';
22
import { toSignal } from '@angular/core/rxjs-interop';
33
import { RouterLink, RouterLinkActive } from '@angular/router';
44
import { FakeServiceService } from './fake.service';
@@ -38,11 +38,7 @@ export class NavigationComponent {
3838
@Component({
3939
imports: [NavigationComponent],
4040
template: `
41-
@if (info() !== null) {
42-
<app-nav [menus]="getMenu(info()!)" />
43-
} @else {
44-
<app-nav [menus]="getMenu('')" />
45-
}
41+
<app-nav [menus]="menus()" />
4642
`,
4743
host: {},
4844
})
@@ -53,10 +49,8 @@ export class MainNavigationComponent {
5349
initialValue: null,
5450
});
5551

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+
]);
6256
}

0 commit comments

Comments
 (0)