Skip to content

Commit 0d3fe2a

Browse files
committed
fix(label.component): Switch from @HostBinding in ngOnInit to computed signal for ID
1 parent 28f94dd commit 0d3fe2a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

projects/novo-elements/src/elements/common/typography/label/label.component.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// NG2
2-
import { Component, computed, input } from '@angular/core';
2+
import { Component, computed, HostBinding, input } from '@angular/core';
33
import { NovoBaseTextElement } from '../base/base-text.component';
44

55
/**
@@ -17,15 +17,19 @@ let nextId = 0;
1717

1818
@Component({
1919
selector: 'novo-label,[novo-label]',
20-
template: ` <ng-content></ng-content> `,
20+
template: `<ng-content></ng-content>`,
2121
styleUrls: ['./label.scss'],
2222
host: {
2323
class: 'novo-label',
24-
'[attr.id]': 'id()',
2524
},
2625
})
2726
export class NovoLabel extends NovoBaseTextElement {
28-
inputId = input(null, { alias: 'id' });
27+
inputId = input<string | null>(null, { alias: 'id' });
2928

30-
id = computed(() => this.inputId() || `novo-label-${++nextId}`);
29+
computedId = computed(() => this.inputId() ?? `novo-label-${++nextId}`);
30+
31+
@HostBinding('attr.id')
32+
get id(): string {
33+
return this.computedId();
34+
}
3135
}

0 commit comments

Comments
 (0)