为什么选择标签没有填充我的 ng 选项
Why isn't the select tag populating my ng-options?
我从服务器返回了数组,并填充了本地$scope.customers(我已经在调试器中验证了这一点);但是,我似乎无法使用数组填充我的选择标签:
角度控制器:
surchargeIndex.controller('SurchargeIndexController', [ "$scope", "customerService", "templateService",
function ($scope, customerService, templateService) {
customerService.getTest().then(function (customers) { $scope.customers = customers; });
//templateService.getTemplates.then(function (templates) { $scope.getTemplates = templates; });
}]);
CSHTML:
<div class="dropdown">
<select ng-model="customerKey" ng-options="customer.Key as customer.Value for customer in customers"></select>
<button id="getTemplates" class="btn btn-primary" ng-click="getTemplates(customerKey)">Get Templates</button>
</div>
当我检查选择元素时,除了一个元素之外什么都没有:
<option value="?" selected="selected"></option>
JSON 字符串:
[
{
Key: 500,
Value: "Test Customer 1"
},
{
Key: 11304,
Value: "test Customer 2"
},
{
Key: 11345,
Value: "Test Customer 3"
},
]
服务:
surchargeIndex.service('customerService', [
'$http', function ($http) {
this.getTest = function () {
return $http({
method: "GET",
url: "api/Customer/GetTest",
})
.success(function(data) {
return data;
});
};
}
]);
我尝试在选项标签上使用 ng-reepat(我意识到这不是首选方式),我得到了 15(数组中的项目数)空白选项。
我错过了什么?
传递给
then
的successCallback
将接收一个表示响应的对象形式的参数。
要使用 data
属性:
customerService.getTest().then(function(result) {
$scope.customers = result.data;
});
或者,您可以改用success
方法。传递给 this 的回调接收四个参数:
success(function(data, status, headers, config) {
例:
customerService.getTest().success(function(data) {
$scope.customers = data;
});
相关文章:
- 如何刷新我的ng重复
- 我的ng include不起作用
- 在角度中,为什么我的 ng-show 不更新以反映当前范围
- 如何将特定信息从外部 API 获取到我的 ng-repeat
- 在AngularyJs中,为什么我的ng模型值没有设置所选选项
- 为什么选择标签没有填充我的 ng 选项
- 为什么 Angular ng-cloak 即使使用自定义指令也会覆盖我的 ng-show
- 为什么我的“ng-click”和“ng-show”需要我传递控制器别名以及正在传递的函数
- AngularJS:如何判断我的控制器是否绑定到我的ng-repeat指令元素?我的数据没有显示
- AngularJS:为什么我的ng选项没有'不要出现
- 为什么我的ng模板没有在angularJS中显示$scope和ng的值
- 为什么我的ng视图动画不起作用
- 我的ng视图与index.html页面angularjs无限循环
- 为什么我的ng类忽略了动画
- 我的ng模型没有't更新我的$scope值
- 当我不希望的时候,我的ng-model允许复制
- 当使用ng-include构建树时,我的'ng-click'不起作用
- 我的ng-change没有在我的Angular/Rails应用上启动
- 为什么我的ng-controller没有被调用?
- AngularJS将我的ng-href "斜杠"到“% 2 f"