I have a custom button like:
<my-button [permission]="'NONE'" [disabled]="!projectForm.valid" type="submit">
Save
</my-button>
If the permissions are 'NONE' I have to disable a button. Therefore I am doing this in directive:
permission.directive.ts
@Input() public readonly permission: string;
constructor(
private readonly element: ElementRef,
private readonly ref: ChangeDetectorRef
) {}
public ngOnInit() {
if (this.permission === 'NONE') {
this.element.nativeElement.disabled = true;
}
}
How ever, it doesn't disable the button. I tried changing the button color and that works perfectly:
this.element.nativeElement.style.color = 'blue';
Since the color changing worked, I thought I might need to trigger the Change Detection:
this.element.nativeElement.disabled = true;
this.element.nativeElement.style.color = 'blue';
The result is still the same, color is changed but the button is not disabled.
Since my-button is a wrapper of button, I tried disabling the button element itself, but the result was the same (Not disabled).
this.element.nativeElement.children[0].disabled = true;
After that I thought since the style.color worked, setting it's style.display to 'none' could also work. Unfortunately that didn't work out either. Does anyone have a clue why changing it's color works perfectly, but changing the disabled or display state doesn't?