In the Angulyar style guide from Tod Motto, there is an example of using the service in the "Presentational logic only (MVVM)" controller:
// recommended function MainCtrl (UserService) { var vm = this; UserService .getUsers() .then(function (response) { vm.users = response; }); vm.removeUser = function (user, index) { UserService .removeUser(user) .then(function (response) { vm.users.splice(index, 1); }); }; } I have long suspected that I am doing something extremely not fashionable, because my factories are so autonomous that the controller is almost out of work. I use factories like this:
function UserService () { var api = { loaded: false getData: getData } return api; function getData() { // Получение данных api.loaded = true; } } function MainCtrl (UserService) { var vm = this; vm.userService = UserService; // Использую api фабрики в контроллере, если нужно получить некие входные данные UserService.getData() } Then I work with the factory directly in the template, calling the necessary methods in the directives (ng-click, ng-mouseover, ng-hide, ...) That is, it turns out simply to forward the factory in view through the controller.
Help cultivate logic in the brain according to which you need to separate the work of the factory from the work of the controller.