diff options
| author | Misko Hevery | 2012-06-06 15:54:40 -0700 |
|---|---|---|
| committer | Misko Hevery | 2013-04-22 23:28:41 -0700 |
| commit | cd38cbf975b501d846e6149d1d993972a1af0053 (patch) | |
| tree | 3857a2879f782c6b7f1350fcd5c8d52e082fd160 /test/ng/directive/ngControllerSpec.js | |
| parent | 021bdf3922b6525bd117e59fb4945b30a5a55341 (diff) | |
| download | angular.js-cd38cbf975b501d846e6149d1d993972a1af0053.tar.bz2 | |
feat(controller): support as instance syntax
Support ng-controller="MyController as my" syntax
which publishes the controller instance to the
current scope.
Also supports exporting a controller defined with route:
````javascript
angular.module('routes', [], function($routeProvider) {
$routeProvider.when('/home', {controller: 'Ctrl as home', templateUrl: '...'});
});
````
Diffstat (limited to 'test/ng/directive/ngControllerSpec.js')
| -rw-r--r-- | test/ng/directive/ngControllerSpec.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/ng/directive/ngControllerSpec.js b/test/ng/directive/ngControllerSpec.js index ab85c569..402ddf09 100644 --- a/test/ng/directive/ngControllerSpec.js +++ b/test/ng/directive/ngControllerSpec.js @@ -3,6 +3,11 @@ describe('ngController', function() { var element; + beforeEach(module(function($controllerProvider) { + $controllerProvider.register('PublicModule', function() { + this.mark = 'works'; + }); + })); beforeEach(inject(function($window) { $window.Greeter = function($scope) { // private stuff (not exported to scope) @@ -27,6 +32,10 @@ describe('ngController', function() { $window.Child = function($scope) { $scope.name = 'Adam'; }; + + $window.Public = function() { + this.mark = 'works'; + } })); afterEach(function() { @@ -41,6 +50,20 @@ describe('ngController', function() { })); + it('should publish controller into scope', inject(function($compile, $rootScope) { + element = $compile('<div ng-controller="Public as p">{{p.mark}}</div>')($rootScope); + $rootScope.$digest(); + expect(element.text()).toBe('works'); + })); + + + it('should publish controller into scope from module', inject(function($compile, $rootScope) { + element = $compile('<div ng-controller="PublicModule as p">{{p.mark}}</div>')($rootScope); + $rootScope.$digest(); + expect(element.text()).toBe('works'); + })); + + it('should allow nested controllers', inject(function($compile, $rootScope) { element = $compile('<div ng-controller="Greeter"><div ng-controller="Child">{{greet(name)}}</div></div>')($rootScope); $rootScope.$digest(); |
