Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabled=false does not work in typescript 2.1

I am trying to disable a field by getting element ID in typescript 2.1. I found this below syntax for typescript 1.5. But it does not work in 2.1. Can anybody help.

( document.getElementById('BenchForcastId_'+valueID)).disabled = false;

like image 382
Green Computers Avatar asked Mar 15 '17 07:03

Green Computers


People also ask

How do I know if a button is disabled in TypeScript?

getElementById(), getElementsByTagName(), etc) to retrieve the button Element (lets assume it has a class of buttonA ). Next, you can simply access its attributes and check its values. If you want to check its disabled attributes, you can simply do check for the value in button['disabled'] .

How do you use NG disability?

Definition and UsageThe ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true. The ng-disabled directive is necessary to be able to shift the value between true and false .

Does not exist on type HTMLElement?

The error "Property 'X' does not exist on type 'HTMLElement'" occurs when we try to access a property that doesn't exist on an element of type HTMLElement . To solve the error, use a type assertion to type the element correctly before accessing the property. This is the index.


1 Answers

If you mean by 'does not work' the fact that compiler will give you an error saying:

Property 'disabled' does not exist on type 'HTMLElement'

Then it is exactly what it says. In order to fix this you can cast it to the type that does have disabled property, for example:

(document.getElementById('BenchForcastId_'+valueID) as HTMLButtonElement).disabled = false;

If you do not know the type (or there can be many different ones) but know for sure that it has disabled property you can cast to any:

(document.getElementById('BenchForcastId_'+valueID) as any).disabled = false;
like image 106
Amid Avatar answered Oct 21 '22 07:10

Amid