在這段代碼中,我調用api。要求是從3 api獲取數據並聚合所有數據並顯示在表中。AngularJs同時調用API我不使用同一函數中的數據
var app = angular.module('myApp',[]);
app.controller('PersonController', function($scope,$http) {
$scope.arr1 =[];
$scope.arr2 = [];
$scope.arr3 = [];
$scope.temp ;
function fetchAllBillable(){
var me =$scope;
$http.get("http://echo.jsontest.com/insert-key-here/insert-value-here/key/value")
.then(function(response) {
$scope.temp = response.data;
console.log(me.temp);
});
return $scope.temp;
the value of scope.temp is undefined
您是否從您的服務獲得回覆? –
是的,我在console.log(me.temp)中獲得響應,它寫在裏面,但沒有在http.get外部得到響應。 –
確保你的return語句應該在函數內部(因爲我不能在你的函數中看到閉括號),並且它正在獲取初始臨時值。 –