我有一个选择框,其中包含来 self 后端的选项:
$http.get($rootScope.appUrl + '/nao/abb/getDataOptionsForAbb/' + $rootScope.abbForm)
.then(function(response) {
$scope.abbOptions = response.data;
//console.log($scope.abbOptions);
});
$scope.onChangeSuperCustomer = function() {
console.log($scope.selectedSupercustomer);
}
我正在使用 ng-options :
<td><select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item.superkund_id as item.namn for item in abbOptions" ng-change="onChangeSuperCustomer()" ><option value=''>Select</option></select></td>
我的 console.log($scope.selectedSupercustomer) 的输出是错误的。这不是我在选择框中选择的值。
最佳答案
试试这个:
<td><select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item.superkund_id as item.namn for item in abbOptions" ng-change="onChangeSuperCustomer(selectedSupercustomer)" ><option value=''>Select</option></select></td>
或者:
<td><select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item.superkund_id as item.namn for item in abbOptions" ng-change="onChangeSuperCustomer()" > <option value=''>Select</option></select></td>
Js:
$scope.onChangeSuperCustomer = function(selectedSupercustomer) {
console.log(selectedSupercustomer);
}
或:
$scope.onChangeSuperCustomer = function() {
console.log($scope.selectedSupercustomer);
}
关于javascript - 在选择框AngularJS中捕获正确的选项数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29623413/