"@angular/core";
@Directive({
selector: "[highlight]",
standalone: true,
})
export class ColorStatusDirective {
public colors = ["gray", "green", "red"];
@Input("status") status?: string;
constructor(el: ElementRef) {
this.changeColor(el);
}
changeColor(el: ElementRef) {
el.nativeElement.style.background = this.colors[Number(this.status)];
}
}
Использую так:
<div class="eec-investigation-status" highlight [status]="'2'">
почему status внутри всегда undefined?
Потому что в конструкторе ещё нет инпут параметров
Почитайте про жизненный цикл компонента
И лучше вам директиву переделать, кмк
поспешил - испарвил
попробуйте OnInit сделать а также сеттер инпут
Обсуждают сегодня