angular.js - 如何获取angularjs中response的返回值?
本文介绍了angular.js - 如何获取angularjs中response的返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如何在外部获得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;
这篇关于angular.js - 如何获取angularjs中response的返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文