I have a directive that helps with adding toggle effects to various elements.
export class AlloyToggleDirective {
private toggled = false;
@Input('alloyToggled')
@HostBinding('class.alloy-toggled')
get isToggled() { return this.toggled; }
set isToggled(value: boolean) {
this.toggled = value;
this.alloyToggledChange.emit(this.toggled);
}
@Output() alloyToggledChange: EventEmitter<boolean> = new EventEmitter();
toggle() {
this.toggled = !this.toggled;
}
@HostListener('click')
onclick() {
this.toggled = !this.toggled;
this.alloyToggledChange.emit(this.toggled);
}
}
It works fine when toggled, however the initial bound value is ignored:
<button [alloyToggled]="booleanValue">
The HTML will reflect that initial value, but the class is only applied after toggling programmatically or via mouse. Is there a strange interaction when @HostBinding
is on an @Input
?