Javascript 在selectbox angularjs中捕获正确的选项数据
我有一个选择框,其中包含来自后端的选项:Javascript 在selectbox angularjs中捕获正确的选项数据,javascript,angularjs,Javascript,Angularjs,我有一个选择框,其中包含来自后端的选项: $http.get($rootScope.appUrl + '/nao/abb/getDataOptionsForAbb/' + $rootScope.abbForm) .then(function(response) { $scope.abbOptions = response.data; //console.log($scope.abbOptions);
$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选项:
<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>
选择
my 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>
或:
$scope.onChangeSuperCustomer = function() {
console.log($scope.selectedSupercustomer);
}
@Anant:我不知道如何使用JSFIDLE:/你的代码应该可以用。。在任何情况下,您都可以使用
$scope重现Plunkr的问题。控制器函数内部的selectedSupercustomer
也应该工作,为什么要将scope值作为函数参数传递
$scope.onChangeSuperCustomer = function(selectedSupercustomer) {
console.log(selectedSupercustomer);
}
$scope.onChangeSuperCustomer = function() {
console.log($scope.selectedSupercustomer);
}