2016年3月11日 星期五

angularjs select not updated , ng-option

This causes by ng-repeat , so use ng-option for instand

=================================
<select ng-model="selected">
 <option value="{{ value }}" ng-repeat="value in items" >{{ value }}</option>
</select>

=================================


<div ng-controller="Controller">
<select ng-options="item as item.label for item in items track by item.id" ng-model="selected">
<option value="" disabled selected>month</option>
</select>
</div>

=================================

<script>
angular.module('docsTemplateUrlDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.items = [{
 id: 1,
 label: 'aLabel',
 subItem: { name: 'aSubItem' }
}, {
 id: 2,
 label: 'bLabel',
 subItem: { name: 'bSubItem' }
}];

$scope.selected = "month";

}])
</script>

沒有留言:

張貼留言