I talked about the new ‘controller as’ syntax before. It allows you to create an alias for your controller on your scope and use that inside your views:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row" ng-controller="ProductsController as vm"> |
If you don’t want to specify your controller inside your view and still want to use the ‘controller as’ syntax, this is also possible. On the $routeProvider an extra property is available which allows you to specify the alias there:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$routeProvider | |
.when('/app/products/add', { templateUrl: '/ProductsApp/AddProduct/add.html', controller: 'addProductController', controllerAs:'product' }); |