aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/directive/ngViewSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2012-06-06 15:54:40 -0700
committerMisko Hevery2013-04-22 23:28:41 -0700
commitcd38cbf975b501d846e6149d1d993972a1af0053 (patch)
tree3857a2879f782c6b7f1350fcd5c8d52e082fd160 /test/ng/directive/ngViewSpec.js
parent021bdf3922b6525bd117e59fb4945b30a5a55341 (diff)
downloadangular.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/ngViewSpec.js')
-rw-r--r--test/ng/directive/ngViewSpec.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ng/directive/ngViewSpec.js b/test/ng/directive/ngViewSpec.js
index e9d53110..3150c040 100644
--- a/test/ng/directive/ngViewSpec.js
+++ b/test/ng/directive/ngViewSpec.js
@@ -55,6 +55,27 @@ describe('ngView', function() {
});
+ it('should instantiate controller with an alias', function() {
+ var log = [], controllerScope,
+ Ctrl = function($scope) {
+ this.name = 'alias';
+ controllerScope = $scope;
+ };
+
+ module(function($compileProvider, $routeProvider) {
+ $routeProvider.when('/some', {templateUrl: '/tpl.html', controller: Ctrl, controllerAlias: 'ctrl'});
+ });
+
+ inject(function($route, $rootScope, $templateCache, $location) {
+ $templateCache.put('/tpl.html', [200, '<div></div>', {}]);
+ $location.path('/some');
+ $rootScope.$digest();
+
+ expect(controllerScope.ctrl.name).toBe('alias');
+ });
+ });
+
+
it('should support string controller declaration', function() {
var MyCtrl = jasmine.createSpy('MyCtrl');