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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With