AngularJS & # 8594; UI router where to define the controller

It is possible to define the controller for the state in the ui router as controller: 'MainController'

, but also this can be omitted and instead the controller can be defined in the view (url pattern) as ng-controller="MainController"

, which is better?

+3


source to share


1 answer


The best practice is to define a controller in the provider config (this also works with the base byte $ routeProvider). It's best to keep your opinion as "clean" as possible.



As @JBNizet is added, this is also the only way the router can inject resolved dependencies into the controller (see the permission property you can pass to your route / state config)

+1


source







All Articles