Imagine that i have to create a User crud, normally i'm create a factory
that contains a save, put, query and delete resources, but pretends that i
have to create 3 pages, one page to new user(save), one page to edit or
delete and one page to list all users.

I am a java programmer so i create one Controller called UserCtrl and i am
grouped all functions in this controller, like this:

App.js
...
.config(function ($routeProvider) {
$routeProvider
.when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' })
.when('/about', { templateUrl: 'views/about.html', controller: 'AboutCtrl'
})
.when('/newUser', { templateUrl: 'views/user/new.html',
controller:'UserController'})
.when('/users', { templateUrl: 'views/user/list.html', controller:
'UserController',})
.when('/user/:id', { templateUrl: 'views/user/edit.html', controller:
'UserController',})
.otherwise({ redirectTo: '/' });
  });

UserCtrl:

angular.module('frontendApp')
.controller('UserController', function ($scope, UsuarioService) {

    //called to create user
    $scope.addUser = function(usuario) {
        UsuarioService.save(usuario);
    };

    $scope.editUser = function(usuario) {
        UsuarioService.put(usuario);
    };

    $scope.delUser = function(usuario) {
        UsuarioService.delete(usuario);
    };

    //here i list all users
    UsuarioService.query(function(data) {
        console.log(data._embedded.usuario);
        $scope.users = data._embedded.usuario; //list users
    });
});

the problem is when i access a page to ADD or EDIT user the query is always
called, and i think that i will have a problem with performance, the best
way to do this is one controller for each operation ? help me xD

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to