Empty Variable Gives True Value To Disabled Attribute On Input February 28, 2024 Post a Comment I dont know if this is a problem or normal behavior. If we have a form like this: field1Solution 1: UPDATEI found the answer to this in the angular source code (<3 open source!). The ngModel controller explicitly checks for '' when the disabled input is changed. If the input strictly equals '', the element will be disabled. So this behavior is by design.Here is how to source code looks (link to GitHub, see line 142 and 217) const isDisabled = disabledValue === '' || (disabledValue && disabledValue !== 'false'); CopyThis means that you cannot use an empty string as falsy to set an input that is using ngModel to disable it. Here is how you get around itBaca JugaAngular 2.0, Typescript And 'form_directives' ModuleWhy The NgStyle Directive Is Declared Into The []?How To Use Questionmark In Url Using Angular 2<inputtype="text" name="field1" [(ngModel)]="mainVar" [disabled]="someVar ? true : false" /> CopyWorking plunker exampleSolution 2: Set it to null/undefined/false, and it will not be disabled. String empty is still a value. Share You may like these postsHow To Get Route Data Into App Component In Angular 2Post From Api With Basic AuthenticationAngular 2+: Internet Explorer: Unable To Get Property 'call' Of Undefined Or Null ReferenceAngular 2 - Restrict Component To Specific Parent Component Post a Comment for "Empty Variable Gives True Value To Disabled Attribute On Input"
Post a Comment for "Empty Variable Gives True Value To Disabled Attribute On Input"