30

I was wondering how I use the Controller as syntax in combination with ngRoute since I cant do ng-controller="Controller as ctrl"

Alex
  • 9,313
  • 1
  • 39
  • 44
user1703761
  • 1,086
  • 3
  • 11
  • 23

2 Answers2

46

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'
    });
Jim Aho
  • 9,932
  • 15
  • 56
  • 87
rob
  • 17,995
  • 12
  • 69
  • 94
40

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'
        });
martinjezek
  • 421
  • 4
  • 3