我正在从角度服务获取休息 api 调用,我需要在角度控制器的任何变量中获取响应数据。所以我可以在视图文件中使用它。这是我的代码:
我的角度 service.js:
angular.module('customerdetails').factory('Detail',['$resource',
function($resource){
return new Customerdetails($resource);
}]);
function Customerdetails( resource ) {
this.getUsers = function( scope ) {
var Customerdetails = resource('/customerdetails');
Customerdetails.query(function(users){
scope.Customerdetails = users;
});
}
}
我的角度控制器:
angular.module('customerdetails').controller('CustomerController',
['$scope', '$rootScope', 'Authentication', 'Detail',
function ($scope, $rootScope, Authentication, Detail) {
$scope.authentication = Authentication;
$scope.users = [];
$scope.find = function(){
Detail.getUsers( $scope )
.success(function (custs) {
$scope.customers = custs;
})
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
//console.log(users,"ppppppp");
};
} ]);
在此我在我的restapi中获取详细信息。当我需要从控制器获取数据以便传入视图文件(html)时,它显示 Detail.getUsers 未定义。
有什么帮助吗?