我使用此控制器在ng-options中选择年份值:
$http.post('http://www.lavorirapidi.it/app/include/profilo.asp?username='+username+'&id='+user_id)
.success(function(data){
$scope.profilo = data;
$scope.nome = username;
})
.error(function(){alert("Errore di comunicazione!")});
$scope.totalyears = 100;
$scope.years = [];
var currentYear = new Date().getFullYear();
for (var i = currentYear; i > currentYear - $scope.totalyears; i--) {
$scope.years.push(i - 1);
}
这是html:
<select class="form-control" ng-model="profilo.anno" ng-options="o for o in years" ng-value="profilo.anno">
<option value="YYYY">YYYY</option>
</select>
但我注意到如果存在ng值(例如1999),则不会在选择菜单上设置!
问题在哪里?!
编辑
我认为我的问题在于控制器!
答案 0 :(得分:0)
试试这个:link
控制器代码:
$scope.totalyears = 100;
$scope.profilo = {anno:2013};
$scope.years = [];
var currentYear = new Date().getFullYear();
for (var i = currentYear; i > currentYear - $scope.totalyears; i--) {
$scope.years.push(i - 1);
}