Reputation: 725
One can define controller for the state in ui router as controller: 'MainController'
, but also this can be omitted, and instead controller can be defined in view (template url) as ng-controller="MainController"
, what is the better practice?
Upvotes: 3
Views: 737
Reputation: 4974
The better practice is to define the controller in the provider configuration (this also works with the core $routeProvider btw). It's best to keep your view as 'clean' as possible.
As @JBNizet added, this is also the only way for the router to inject the resolved dependencies into the controller (see the resolve property that you can pass into your route/state config)
Upvotes: 1