我在将下拉过滤器($ scope.selectedOperation.OP_NAME)的结果绑定到Web服务时出现问题,以便在页面加载时显示结果。我一直收到一条错误,上面写着"无法读取未定义的属性OP_NAME。"即使我将结果记录到控制台,一切看起来都是正确的。请帮忙!
var headcountsApp = angular.module('headcountsApp', []);
headcountsApp.controller('headcountsController', ['$scope', '$http',
function($scope, $http) {
$scope.selectOperations = [];;
//Data for drop-down filters
$scope.getOpFilter = function() {
var dtaArray = {};
$http.post("/services/SA.svc/getOpName", dtaArray).then(function onSuccess(response) {
$scope.opFilter = JSON.parse(response.data.getOpNameResult);
angular.forEach($scope.opFilter, function(value, key) {
$scope.selectOperations.push(value);
});
$scope.selectedOperation = $scope.selectOperations[0];
});
};
$scope.corpArray = [];
$scope.getCorp = function() {
var dtaArray = {};
dtaArray.OP_NAME = $scope.selectedOperation.OP_NAME;
var dtaJson = JSON.stringify(dtaArray);
$http.post("/services/SA.svc/getCorpHeadCounts",
dtaArray).then(function onSuccess(response) {
$scope.corporateSummary =
JSON.parse(response.data.getCorpHeadCountsResult);
angular.forEach($scope.corporateSummary, function(value, key) {
$scope.corpArray.push(value);
});
});
};
angular.element(document).ready(function() {
$scope.getOpFilter();
$scope.getCorp();
});
}]);
答案 0 :(得分:0)
Please remove last line angular.element(document).ready(function() { } call $scope.getOpFilter() after getOpFilter function and $scope.getCorp() after getCorp function.