I have a simple custom directive that needs to make the element disabled.
<button mat-button [myCustomDirective]="'mode1'">Edit</button>
@Directive({
selector: '[myCustomDirective]'
})
export class MyCustomDirective implements OnInit {
@Input() myCustomDirective: string;
@Input()
@HostBinding('disabled')
public disabled: boolean;
constructor(
private el: ElementRef,
private cd: ChangeDetectorRef
) {}
ngOnInit() {
switch (this.myCustomDirective) {
case 'mode1':
this.disabled = true;
this.el.nativeElement.disabled = true;
setTimeout(() => {
this.cd.markForCheck();
this.cd.detectChanges();
});
break;
default:
this.el.nativeElement.remove();
break;
}
}
}
Even if the disabled attribute appears in the DOM, the mat-button doesn't get fully update ( the disabled styles are missing, because some of the disabled classes that angular material haves for the mat-button are missing also from the DOM ). So mat-button doesn't updates. Any suggestions for this ?