-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathnav-button.component.ts
More file actions
28 lines (25 loc) · 737 Bytes
/
nav-button.component.ts
File metadata and controls
28 lines (25 loc) · 737 Bytes
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
/* eslint-disable @angular-eslint/component-selector */
import { Component, computed, input } from '@angular/core';
import { RouterLink } from '@angular/router';
@Component({
selector: 'nav-button',
imports: [RouterLink],
template: `
<a [routerLink]="routerLink()" [fragment]="fragment()">
<ng-content />
</a>
`,
host: {
class: 'block w-fit border border-red-500 rounded-md p-4 m-2',
},
})
export class NavButtonComponent {
href = input('');
isAnchorLink = computed(() => this.href().startsWith('#'));
routerLink = computed(() => {
return this.isAnchorLink() ? [] : this.href();
});
fragment = computed(() => {
return this.isAnchorLink() ? this.href().substring(1) : undefined;
});
}