(function(angular) {
'use strict';
angular.module('myApp', [])
.controller('Controller', [function() {
this.model = {
person: {
titleId: 4
}
}
}]);
})(window.angular);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="Controller as nb">
<select ng-model="nb.model.person.titleId">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4">D</option>
</select>
<p>{{nb.model.person.titleId}}</p>
</div>
</div>
When I select A, B, C or D the model value is updated as expected. person has a titleId value between 1 and 4.
However when loading up a new model, with a titleId.
{
"person": {
"titleId": 4
}
}
The select is not being set to the correct value. The model binding seems to be working 1 way, and not 2 way?
Is there an easy way to fix this?