如何在外部獲得response的值?
app.controller('postCtrl', ['$scope', 'myservice', function($scope, myservice){
myservice.getData().success(function(res){
$scope.posts = res.records;
console.log($scope.posts); //这个有输出
});
console.log($scope.posts); //这个却显示undefined
}]);
app.factory('myservice', ['$http', function($http){
return {
getData: function(){
return $http.get("post_info.php");
}
}
}]);
首先是作用域問題,要想外部存取可以試試$rootScope.posts=res.records;
雷雷
https://code.angularjs.org/1....$http