From b3777f275c6bd2bd4a88963fd03828eb7cf3aca8 Mon Sep 17 00:00:00 2001 From: Lucas Galfasó Date: Fri, 24 May 2013 21:18:51 -0300 Subject: feat(directive): support as instance syntax Support controller: 'MyController as my' syntax for directives which publishes the controller instance to the directive scope. Support controllerAs syntax to define an alias to the controller within the directive scope. --- test/ng/compileSpec.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test') diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 45502b26..c2827559 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2244,6 +2244,52 @@ describe('$compile', function() { }); + iit('should support controllerAs', function() { + module(function() { + directive('main', function() { + return { + templateUrl: 'main.html', + transclude: true, + scope: {}, + controller: function() { + this.name = 'lucas'; + }, + controllerAs: 'mainCtrl' + }; + }); + }); + inject(function($templateCache, $compile, $rootScope) { + $templateCache.put('main.html', 'template:{{mainCtrl.name}}
'); + element = $compile('
transclude:{{mainCtrl.name}}
')($rootScope); + $rootScope.$apply(); + expect(element.text()).toBe('template:lucas transclude:'); + }); + }); + + + it('should support controller alias', function() { + module(function($controllerProvider) { + $controllerProvider.register('MainCtrl', function() { + this.name = 'lucas'; + }); + directive('main', function() { + return { + templateUrl: 'main.html', + scope: {}, + controller: 'MainCtrl as mainCtrl' + }; + }); + }); + inject(function($templateCache, $compile, $rootScope) { + $templateCache.put('main.html', '{{mainCtrl.name}}'); + element = $compile('
')($rootScope); + $rootScope.$apply(); + expect(element.text()).toBe('lucas'); + }); + }); + + + it('should require controller on parent element',function() { module(function() { directive('main', function(log) { -- cgit v1.2.3