0
我有以下Angular控制器。我想从x
和y
变量中获取物品并将其显示在网页上。目前,该网页仅显示y
变量中的项目。我尝试使用.push()
将两个函数结果集放在一起到PremByClass
数组中。任何帮助或方向如何做到这一点将不胜感激。试图在Angular.js或JavaScript中加入两个函数返回值
app.controller('PremByClass', ['$scope', '$http', 'policyApi', 'lookupApi', function ($scope, $http, policyApi, lookupApi) {
$scope.model = {};
$scope.load.then(function() {
function formatDate(value) {
return value.getMonth() + 1 + "-" + value.getDate() + "-" + value.getFullYear();
}
$scope.PremByClass = [];
policyApi.policy.get().then(function (t) {
if (t) {
policyApi.class.get().then(function (x) {
if (x) {
//Put x into $scope.PremByClass
$scope.PremByClass.push(x);
var dtEff = formatDate(t.DateEffective);
for (var i = 0, e = null; e = x[i]; i++) {
lookupApi.WCClassDesc.get(e.GovState, e.classCode, e.DescCode, dtEff).then(function (y) {
//This seems to wrok correctly however it seems that $scope.PremByClass forgets about x
//The web page only shows stuff from y
$scope.PremByClass.push(y);
})
}
}
})
}
})
});
}]);