How to enble/disable a button in TypeScript 1.5?
There should be a cleaner way to do this:
var element = <HTMLInputElement> document.getElementById("btnExcel");
element.disabled = true;
Or if you prefer a one liner:
(<HTMLInputElement> document.getElementById("btnExcel")).disabled = true;
It seems getElementById
and the like should be a generic method and accept a type parameter. That said, a generic method wouldn't give you anything that typecasting doesn't.
I'm using "typescript": "~3.8.3" in Angular 9. To disable a button successfully try:
let button = <HTMLButtonElement> document.getElementById('confirmBtn');
button.disabled = true;
I'm using TypeScript v 3.7.something. In here
(document.getElementById('button') as HTMLInputElement).disabled = false;
is prefered. (guided by @Martin's answer)