【发布时间】:2015-06-26 09:09:06
【问题描述】:
app.controller('EntryCtrl', ['$scope', '$http', function($scope, $http){
$http.get(something.json).success(function(data){
$scope.entries = data;
});
abc = $scope.entries.timestamp; <-- not working
}]);
经过搜索,发现$http是一个异步函数。所以我把它包装成一个函数,但还是不行。
app.controller('EntryCtrl', ['$scope', '$http', function($scope, $http){
var getEntries = function(){ return
$http.get(something.json).success(function(data){
return data;
});
};
$scope.entries = getEntries();
console.log($scope.entries); // returns undefined
}]);
【问题讨论】:
标签: angularjs angularjs-scope angularjs-controller angular-http angularjs-http