I was wondering how I use the Controller as
syntax in combination with ngRoute
since I cant do ng-controller="Controller as ctrl"
"Controller as" syntax for ng-view
You can use the controller as
syntax when you specify your controller in the $routeProvider
configuration.
e.g.
$routeProvider
.when('/somePath', {
template: htmlTemplate,
controller: 'myController as ctrl'
});
Or, you can specify a controller assigning like when you create a new directive using controllerAs
.
$routeProvider
.when('/products', {
templateUrl: 'partials/products.html',
controller: 'ProductsController',
controllerAs: 'products'
});
I think your approach is a lot cleaner –
Oppidan
Exactly, when implementing, please prefer this solution –
Bulimia
© 2022 - 2024 — McMap. All rights reserved.