Angular 2 Bilateral Binding with [Disabled]

I have an input with [disabled]depending on ngModelanother input. Initially it [disabled]works correctly, but not when we change the dependent input value, the property [disabled]does not work. How to apply two bindings to a property [disabled]?

Below is a snippet of code.

<select [ngModel]="isDisabled" (ngModelChange)="isDisabled=$event">
<option value="0">Disabled</option>
<option value="0">Enabled</option>
</select>

This model is isDisabledmodified correctly. I could see a change in value similar to this in the template {{isDisabled}}. But it does not appear in [disabled]the selection field property .

<select [ngModel]="userInput" [disabled]="isDisabled">
<option value="test">Test</option>
</select>
+4
source share
4 answers

, value 0 . 1 0 Enable Disable. , value '0' ( '0') '1' ( 1) ( ).

dataType ngValue.

<select [ngModel]="isDisabled" (ngModelChange)="isDisabled=$event">
  <option [ngValue]="1">Disabled</option>
  <option [ngValue]="0">Enabled</option>
</select>

-

+1

ng-mode, . ngModelChange

<select [(ngModel)]="isDisabled"  name='isDisabled'>
        <option value="0">Disabled</option>
        <option value="1">Enabled</option>
</select>
<select [(ngModel)]="userInput" [disabled]="isDisabled == '0'" name='userInput'>
        <option value="test">Test</option>
</select>
+1

true\false [disabled], .

<select [(ngModel)]="isDisabled">
        <option value="true">Disabled</option>
        <option value="false">Enabled</option>
</select>

<select [ngModel]="userInput" [disabled]="isDisabled">
     <option value="test">Test</option>
</select>

Plunker

0

0.

You want to make sure one trueand the otherfalse


component:

component class {
    myVar = false
}

Template:

<select [(ngModel)]="myVar">
    <option value="true">...</option
    <option value="false">...</option
</select>

<select [disabled]="myVar">
    <option>...</option
</select>
0
source

Source: https://habr.com/ru/post/1678319/


All Articles