How may I add disabled
to an input
if a condition is met?
What I have today:
<input class="previous" [attr.disabled] = "active === 1 ? 'disabled' : ''">
But this adds disabled="disabled"
and I want only disabled
.
So what I need is: <input class="previous" disabled>
if the condition is met.
The 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 .
the button will be disabled when valid is false and the angular formGroup , SAForm is not valid. A recommendation here as well, Please make the button of type button not a submit because this may cause the whole form to submit and you would need to use invalidate and listen to (ngSubmit) .
To disable elements just use attribute disabled rather than true or false. To enable it again, you need to remove the disabled attribute. In your code [attr. disabled] is setting the value to true or false, what you need is just use [disabled] instead of [attr.
Can't bind to 'readOnly' since it isn't a known property of 'ng-select'. If 'ng-select' is an Angular component and it has 'readOnly' input, then verify that it is part of this module. If 'ng-select' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.
An attribute can be removed by passing the value null
[attr.disabled] = "active === 1 ? 'disabled' : null">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With