AngularJS <select> DOM markup

I am curious to use ng-options and ng-model to set the selected item for the model, why the Angular DOM markup does not display the correct value, but the correct value is still displayed.

  $scope.myArray = [{ value: 'Yes' }, { value: 'No' }];

  $scope.cboModel.myArrayValSel = // Json pulled and value set from JS proxy call;

  <select ng-model="cboModel.myArrayValSel " ng-options="val.value as val.value for val in myArray " /> 

DOM markup renders:

<option selected="selected" value="0" label="Yes">Yes</option>
<option value="1" label="No">No</option>

So, if the value is returned as “No” for the property of the object model, it is displayed in the drop-down list respectively in the browser, but I don’t understand why it does not set the selected = “selected” attribute to the second element in the array. In this case, on

<option value="1" label="No">No</option>.  

, , HTML PDF. PDF , , , , , PDF.

+2
1

selected ( , $scope.cboModel.myArrayValSel).

<option> value, track by,

ng-options="val.value for val in myArray track by val.value"

Plunker


, ng-model , (, 'Yes' 'No').

,

$scope.choice = $scope.myArray[0];
+3

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


All Articles