I wand to add a class to a div based on two condidions. For this I created a directive like this:
import { Directive, HostBinding, Input } from '@angular/core';
@Directive({
selector: '[confirmdialog-style]',
})
export class ConfirmDialogStyleDirective {
@Input() isMsgDialog!: boolean;
@Input() dialogType!: string;
@HostBinding('class')
elementClass = this.isMsgDialog ? 'x-' + this.dialogType : '';
}
And I use it like this:
<div
class="x-dialog-container"
confirmdialog-style
[isMsgDialog]="isMsgDialog"
[dialogType]="dialogType"
>
I set the isMsgDialog and dialogType properties in the parent component via button click. The two input properties are set correctly, as I checked it via chrome debug tools.
The issue is, that the desired class (f. e. x-danger) isn't added to the div. Why doesn't this work?