【发布时间】:2017-05-21 04:50:41
【问题描述】:
我在理解 Angular 中的下拉功能时遇到了一些麻烦。
我已尝试关注 StackOverflow 中的这些帖子,但我被卡住了:
How can I populate a select dropdown list from a JSON feed with AngularJS?
Angular js Populate dropdown with JSON
我能够填充下拉列表的唯一方法是在每一行中显示所有值(违背其目的): + 到目前为止我的代码:
HTML:
<div align = "left" ng-controller='DemoCtrl'>
<select ng-model="tiposProduto" >
<option value="">Selecione o tipo de produto:</option>
<option ng-repeat ="selectedTestAccount in testAccounts" value="item.Id"> {{testAccounts}}>
</select>
</div>
Javascript:
<script src="js/app.js"></script>
<script>
app.controller('DemoCtrl', function ($scope, $http) {
$scope.selectedTestAccount = null;
$scope.testAccounts = [];
$http({ method: 'GET', url: '//localhost:8080/RestfulWebservice/rs/service/getTodosTiposProduto'
}).success(function (result) {
$scope.testAccounts = result.tiposProduto;
});
});
</script>
所以,我不确定 ng-repeat 行应该做什么。如果我尝试将它们记录在控制台中,“items”和“selectedTestAccount”都是未定义的。
范围是这样的(testAccount 值是我想要填充为行的值):
有人可以帮帮我吗?
【问题讨论】:
-
SelectedTestAccount 不应在控制器中声明。什么是物品?
标签: javascript html angularjs drop-down-menu