You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
I have the issue with Angular.js v1.3.11 and ng-options directive. The problem is next. I have a model value I know ahead but data for binding of options comes in Ajax request later and Angular.js produces that as two selected options: with my value and first one.
Html
<body ng-controller="MainCtrl">
<select ng-model="selectedYear" ng-options="o.year as o.year for o in options"></select>
</body>
Javascript
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $timeout) {
// Known value for preselection
$scope.selectedYear = 2013;
$scope.options = [];
// Ajax call emulation
$timeout(function() {
$scope.options = [{year: 2012}, {year: 2013}, {year: 2014}];
});
});
Output
<select ng-model="selectedYear" ng-options="o.year as o.year for o in options" class="ng-pristine ng-valid ng-touched">
<option value="0" selected="selected" label="2012">2012</option>
<option value="1" selected="selected" label="2013">2013</option>
<option value="2" label="2014">2014</option>
</select>
There's an unfortunate number of bugs in ngOptions 1.3.x. Most of them have been fixed in the 1.4.x branch, and would be very difficult to fix without breaking changes in 1.3
I have the issue with Angular.js v1.3.11 and ng-options directive. The problem is next. I have a model value I know ahead but data for binding of options comes in Ajax request later and Angular.js produces that as two selected options: with my value and first one.
Html
Javascript
Output
Plunker
http://plnkr.co/edit/gFZ8Z7T5DhDPvk4G9tEU?p=preview
Stackoverflow
http://stackoverflow.com/questions/29858677/predefined-model-value-and-ng-options-later-binding/
The text was updated successfully, but these errors were encountered: