From 3c608dd77e4d869181c644cf9645446c6f437b03 Mon Sep 17 00:00:00 2001 From: Jakub Torbicki Date: Wed, 18 Mar 2015 10:16:14 +0100 Subject: [PATCH] fix for #11343 - bindToController for multiple directives - test added --- test/ng/compileSpec.js | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index b89f1d08312c..70ea02e93332 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -4033,6 +4033,68 @@ describe('$compile', function() { }); + it('should bind to multiple directives controllers via object notation (new scope)', function() { + var controllerCalled = false; + var secondControllerCalled = false; + module(function($compileProvider, $controllerProvider) { + $controllerProvider.register('myCtrl', function() { + expect(this.data).toEqualData({ + 'foo': 'bar', + 'baz': 'biz' + }); + expect(this.str).toBe('Hello, world!'); + expect(this.fn()).toBe('called!'); + controllerCalled = true; + }); + $controllerProvider.register('secondCtrl', function() { + expect(this.data).toEqualData({ + 'foo2': 'bar2', + 'baz2': 'biz2' + }); + expect(this.str).toBe('Hello, second world!'); + expect(this.fn()).toBe('second called!'); + secondControllerCalled = true; + }); + $compileProvider.directive('fooDir', valueFn({ + bindToController: { + 'data': '=dirData', + 'str': '@dirStr', + 'fn': '&dirFn' + }, + scope: true, + controller: 'myCtrl as myCtrl' + })); + $compileProvider.directive('barDir', valueFn({ + bindToController: { + 'data': '=barData', + 'str': '@barStr', + 'fn': '&barFn' + }, + scope: true, + controller: 'secondCtrl as secondCtrl' + })); + }); + inject(function($compile, $rootScope) { + $rootScope.fn = valueFn('called!'); + $rootScope.whom = 'world'; + $rootScope.remoteData = { + 'foo': 'bar', + 'baz': 'biz' + }; + $rootScope.fn2 = valueFn('second called!'); + $rootScope.whom2 = 'second world'; + $rootScope.remoteData2 = { + 'foo2': 'bar2', + 'baz2': 'biz2' + }; + element = $compile('
')($rootScope); + $rootScope.$digest(); + expect(controllerCalled).toBe(true); + expect(secondControllerCalled).toBe(true); + }); + }); + + it('should put controller in scope when controller identifier present but not using controllerAs', function() { var controllerCalled = false; var myCtrl;