toddmotto / angularjs-styleguide

AngularJS styleguide for teams
https://ultimateangular.com
5.96k stars 700 forks source link

Can you explain why we should not bind resolve logic to the router? #38

Closed aarongray closed 9 years ago

aarongray commented 9 years ago

Here it talks about putting our resolves in the controller, instead of in the router. This is interesting to me, because I thought that you wanted to keep your controllers as slim as possible (as a general rule, and in prep for Angular 2.0). Can you elaborate a little more about why you would want to put your resolve logic inside a controller?

Thanks! ^_^

toddmotto commented 9 years ago

It's essentially coupling the correct logic in the correct file. The routing logic isn't "in" the Controller, but becomes a property of:

function SomeCtrl() {

}
SomeCtrl.resolve = {
  prop: function (Service) {
    return Service.resolve();
  }
};

If you've a huge application, then you've got a huge mash of Service calls all over your router, instead of managing them as "components" inside the relevant files. I hope that helps somewhat.

aarongray commented 9 years ago

Thanks man. Cool styleguide. ^_^