forked from tomalaforge/angular-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain-navigation.component.ts
More file actions
62 lines (57 loc) · 1.35 KB
/
Copy pathmain-navigation.component.ts
File metadata and controls
62 lines (57 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Component, inject, input } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { FakeServiceService } from './fake.service';
interface MenuItem {
path: string;
name: string;
}
@Component({
selector: 'app-nav',
imports: [RouterLink, RouterLinkActive],
template: `
@for (menu of menus(); track menu.path) {
<a
class="rounded-md border px-4 py-2"
[routerLink]="menu.path"
routerLinkActive="isSelected">
{{ menu.name }}
</a>
}
`,
styles: `
@reference "tailwindcss";
a.isSelected {
@apply bg-gray-600 text-white;
}
`,
host: {
class: 'flex flex-col p-2 gap-2',
},
})
export class NavigationComponent {
menus = input.required<MenuItem[]>();
}
@Component({
imports: [NavigationComponent],
template: `
@if (info() !== null) {
<app-nav [menus]="getMenu(info()!)" />
} @else {
<app-nav [menus]="getMenu('')" />
}
`,
host: {},
})
export class MainNavigationComponent {
private fakeBackend = inject(FakeServiceService);
readonly info = toSignal(this.fakeBackend.getInfoFromBackend(), {
initialValue: null,
});
getMenu(prop: string) {
return [
{ path: '/foo', name: `Foo ${prop}` },
{ path: '/bar', name: `Bar ${prop}` },
];
}
}