A
A
Abc Edc2014-12-22 19:26:27
Angular
Abc Edc, 2014-12-22 19:26:27

How to organize everything in AngularJs?

Suppose there is a certain UserCntrl controller, which, for example, registers a user at a minimum or logs him in, and something else. And there is a factor, as I understand it, it is she who acts as a model here, well, in the sense of not a database model, but the one that accesses the api (maybe I’m talking nonsense, I’m only studying angular for a couple of days) UserFctr
So is it worth organizing like this: i.e. create one large controller for the model (factory) User and in it some kind of enumeration to do on the method and already call it there in the factor

angular
.module('starter', [])
.controller('UserCntrl', ['$scope', 'User', function($scope,  User) {
    for (var key in $scope) { 
        switch (key) 
        case 'register':
        вызываем User(с данными)
        [break]
   case 'Login':
      вызываем User(с данными)
        [break]
   ...
   case labelN:
      statementsN
      [break]
}
     } 

}])  или лучше сделать много разных контроллеров для User(фактори)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2014-12-22
@gleber1

Yes, you can without enumeration ( switch case ). So it’s clearer and you can’t run into a rake with a running start :)
And so it’s quite a normal practice!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question