这里是我的代码
app.controller('adminControl', ['$scope','$routeParams','$route','adminService', function($scope,$routeParams,$route,adminService){
$scope.data = adminService.listOfAdmin();
console.log($scope.data);
}]).service('adminService', ['$http', function($http){
this.get = function(url){
return $http({
method:'GET',
url:url
}).then(function(response){
return response;
});
}
this.listOfAdmin = function(){
this.get('http://localhost/project/s9/ayu/admin/sys/mac.php?act=administrator')
.then(function(response){
return response.data;
});
}
}]);
答案 0 :(得分:0)
您必须返回承诺并等待该承诺完成。
app.controller('adminControl', ['$scope','$routeParams','$route','adminService', function($scope,$routeParams,$route,adminService){
$scope.data = adminService.listOfAdmin().then(function(response) {
console.log(response.data);
});
}]).service('adminService', ['$http', function($http){
this.get = function(url){
return $http({
method:'GET',
url:url
});
}
this.listOfAdmin = function(){
return this.get('http://localhost/project/s9/ayu/admin/sys/mac.php?act=administrator');
}
}]);
答案 1 :(得分:0)
它返回一个promise,并且应该在解析promise之后设置数据:
app.controller('adminControl', ['$scope','$routeParams','$route','adminService', function($scope,$routeParams,$route,adminService){
adminService.listOfAdmin().then(function(data) {
$scope.data = data;
console.log($scope.data);
});
}]).service('adminService', ['$http', function($http){
this.get = function(url){
return $http({
method:'GET',
url:url
}).then(function(response){
return response;
});
}
this.listOfAdmin = function(){
return this.get('http://localhost/project/s9/ayu/admin/sys/mac.php?act=administrator')
.then(function(response){
return response.data;
});
}
}]);