我在.js
文件中有以下内容。我是棱角分明的新手。现在不是单独写这个,而是希望它在一个服务中说Practices
。
怎么做?
angular.module('myApp').factory('Practices', ['$resource', function ($resource) {
return $resource('/api/practices/:statusController/:statusId/:searchController/:searchId/:practiceId/:pageController/:pagenum', {
practiceId: '@practiceId',
statusId: '@statusId',
statusController: '@statusController',
searchId: '@searchId',
searchController: '@searchController',
pagenum: '@pagenum',
pageController: '@pageController'
});
}]);
angular.module('myApp')
.factory('PracticesEdit', function ($resource) {
return {
UpdatePractice: function () {
return $resource('/api/practicesUpdate/:practiceId', {
practiceId: '@_id'
}, { //parameters default
update: {
method: 'PUT'
}
});
},
UpdateCreditCard: function () {
return $resource('/api/practicesCreditCardUpdate/:practiceId', {
practiceId: '@_id'
}, { //parameters default
updateCredit: {
method: 'PUT'
}
});
}
}
});
答案 0 :(得分:1)
angular.module('myApp').factory('PracticesService', function ($resource) {
var practices = $resource(...);
return {
updatePractice: function () {
// the same
},
updateCreditCard: function () {
// the same
},
practices: practices
}
});
然后你可以在控制器中使用它
PracticesService.practices;
PracticesService.updateCreditCard();
PracticesService.updatePractice();