mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 21:33:02 -05:00
21 lines
548 B
TypeScript
21 lines
548 B
TypeScript
/* eslint-disable @angular-eslint/directive-selector */
|
|
/* eslint-disable @angular-eslint/no-host-metadata-property */
|
|
import { Directive, WritableSignal, signal } from '@angular/core';
|
|
|
|
export type ButtonState = 'enabled' | 'disabled';
|
|
|
|
@Directive({
|
|
selector: 'button[btnDisabled]',
|
|
standalone: true,
|
|
host: {
|
|
'(click)': 'toggleState()',
|
|
},
|
|
})
|
|
export class BtnDisabledDirective {
|
|
state: WritableSignal<ButtonState> = signal('enabled');
|
|
|
|
toggleState() {
|
|
this.state.set(this.state() === 'enabled' ? 'disabled' : 'enabled');
|
|
}
|
|
}
|