【发布时间】:2017-07-10 21:16:24
【问题描述】:
我在为选择下拉列表设置 ng-model 时遇到了这个相当奇怪的问题。
我用于ng-model 的属性值似乎与ng-options 中的条目匹配,但ng-model 总是以null 结尾。
这是获取订单的方法:
orderService.getMerchantOrders(qs)
.then(
function (response) {
$scope.isLoading = false;
$scope.pagerService = new pagerService({
page: $scope.pagerService.page,
data: response.data.items,
total: response.data.total,
sortVars: response.data.sort,
pageSize: 5
});
},
function (error) {
if (error.status === 401) {
$window.location.href = $scope.returnUrl;
} else {
//show error message
console.log(error);
}
});
order.orderShippingMethod[0].shippingMethod 的值为:
{"shippingMethodId":7,"carrierName":"Russian Post","carrierUrl":"http://www.russianpost.ru/tracking20/English.htm","orderShippingMethod":[]}
感谢您的任何想法。我是 AngularJs 的初学者,所以我觉得这是我在这里缺少的非常简单的东西!
<select class="form-control" name="carrierList"
ng-model="order.orderShippingMethod[0].shippingMethod"
ng-options="shippingMethod.shippingMethodId as shippingMethod.carrierName
for shippingMethod in shippingMethods" required>
<option value="">Select Carrier</option>
</select>
【问题讨论】:
-
您应该添加一些代码来说明您当前围绕您提供的 sn-p 所拥有的内容。您应该显示 $scope.order 的定义位置,以及 $scope.order.orderShippingMethod(s) 的定义位置。
-
好主意,更新了更多细节!
标签: javascript angularjs html-select ng-options angularjs-ng-model