次の角度コントローラがあります。私はx
とy
の両方の変数から項目を取り出し、それらをウェブページに表示したいと思います。現在、ウェブページにはy
変数の項目のみが表示されます。 .push()
を使用して、2つの関数結果セットをまとめてPremByClass
配列に入れようとします。これを行う方法に関する助言や指示があれば大いに感謝します。Angular.jsまたはJavaScriptで2つの関数リターンを結合しようとしています
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);
})
}
}
})
}
})
});
}]);