fix(ngController): change controllerAlias to controllerAs.

This commit is contained in:
Misko Hevery 2013-04-29 14:27:45 -04:00
parent 7812ae75d5
commit 400f9360bb
3 changed files with 7 additions and 7 deletions

View file

@ -105,12 +105,12 @@
$routeProvider.when('/Book/:bookId', {
templateUrl: 'book.html',
controller: BookCntl,
controllerAlias: 'book'
controllerAs: 'book'
});
$routeProvider.when('/Book/:bookId/ch/:chapterId', {
templateUrl: 'chapter.html',
controller: ChapterCntl,
controllerAlias: 'chapter'
controllerAs: 'chapter'
});
// configure html5 to get links working on jsfiddle
@ -204,8 +204,8 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c
if (current.controller) {
locals.$scope = lastScope;
controller = $controller(current.controller, locals);
if (current.controllerAlias) {
lastScope[current.controllerAlias] = controller;
if (current.controllerAs) {
lastScope[current.controllerAs] = controller;
}
element.children().data('$ngControllerController', controller);
}

View file

@ -44,8 +44,8 @@ function $RouteProvider(){
* - `controller` `{(string|function()=}` Controller fn that should be associated with newly
* created scope or the name of a {@link angular.Module#controller registered controller}
* if passed as a string.
* - `controllerAlias` `{string=}` A controller alias name. If present the controller will be
* published to scope under the `controllerAlias` name.
* - `controllerAs` `{string=}` A controller alias name. If present the controller will be
* published to scope under the `controllerAs` name.
* - `template` `{string=|function()=}` html template as a string or function that returns
* an html template as a string which should be used by {@link ng.directive:ngView ngView} or
* {@link ng.directive:ngInclude ngInclude} directives.

View file

@ -63,7 +63,7 @@ describe('ngView', function() {
};
module(function($compileProvider, $routeProvider) {
$routeProvider.when('/some', {templateUrl: '/tpl.html', controller: Ctrl, controllerAlias: 'ctrl'});
$routeProvider.when('/some', {templateUrl: '/tpl.html', controller: Ctrl, controllerAs: 'ctrl'});
});
inject(function($route, $rootScope, $templateCache, $location) {