I was wondering how I use the Controller as
syntax in combination with ngRoute
since I cant do ng-controller="Controller as ctrl"
我想知道如何将控制器与ngRoute结合使用作为语法,因为我不能将ng-controller="Controller ="作为ctrl"
2 个解决方案
#1
44
You can use the controller as
syntax when you specify your controller in the $routeProvider
configuration.
在$routeProvider配置中指定控制器时,可以使用控制器作为语法。
e.g.
如。
$routeProvider
.when('/somePath', {
template: htmlTemplate,
controller: 'myController as ctrl'
});
#2
38
Or, you can specify a controller assigning like when you create a new directive using controllerAs
.
或者,您可以指定一个控制器赋值,比如使用controllerAs创建新指令时。
$routeProvider
.when('/products', {
templateUrl: 'partials/products.html',
controller: 'ProductsController',
controllerAs: 'products'
});
#1
44
You can use the controller as
syntax when you specify your controller in the $routeProvider
configuration.
在$routeProvider配置中指定控制器时,可以使用控制器作为语法。
e.g.
如。
$routeProvider
.when('/somePath', {
template: htmlTemplate,
controller: 'myController as ctrl'
});
#2
38
Or, you can specify a controller assigning like when you create a new directive using controllerAs
.
或者,您可以指定一个控制器赋值,比如使用controllerAs创建新指令时。
$routeProvider
.when('/products', {
templateUrl: 'partials/products.html',
controller: 'ProductsController',
controllerAs: 'products'
});