From c173ca412878d537b18df01f39e400ea48a4b398 Mon Sep 17 00:00:00 2001 From: Chirayu Krishnappa Date: Fri, 9 Aug 2013 19:56:10 -0700 Subject: fix($compile): correct controller instantiation for async directives This fixes regression introduced by #3514 (5c560117) - this commit is being reverted here and a better fix is included. The regression caused the controller to be instantiated before the isolate scope was initialized. Closes #3493 Closes #3482 Closes #3537 Closes #3540 --- test/ng/compileSpec.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'test/ng/compileSpec.js') diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 36a8b990..ba94c48b 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2455,6 +2455,61 @@ describe('$compile', function() { }); + it('should instantiate the controller after the isolate scope bindings are initialized (with template)', function () { + module(function () { + var Ctrl = function ($scope, log) { + log('myFoo=' + $scope.myFoo); + }; + + directive('myDirective', function () { + return { + scope: { + myFoo: "=" + }, + template: '

Hello

', + controller: Ctrl + }; + }); + }); + + inject(function ($templateCache, $compile, $rootScope, log) { + $rootScope.foo = "bar"; + + element = $compile('
')($rootScope); + $rootScope.$apply(); + expect(log).toEqual('myFoo=bar'); + }); + }); + + + it('should instantiate the controller after the isolate scope bindings are initialized (with templateUrl)', function () { + module(function () { + var Ctrl = function ($scope, log) { + log('myFoo=' + $scope.myFoo); + }; + + directive('myDirective', function () { + return { + scope: { + myFoo: "=" + }, + templateUrl: 'hello.html', + controller: Ctrl + }; + }); + }); + + inject(function ($templateCache, $compile, $rootScope, log) { + $templateCache.put('hello.html', '

Hello

'); + $rootScope.foo = "bar"; + + element = $compile('
')($rootScope); + $rootScope.$apply(); + expect(log).toEqual('myFoo=bar'); + }); + }); + + it('should instantiate controllers in the parent->child->baby order when nested transluction, templateUrl and ' + 'replacement are in the mix', function() { // similar to the test above, except that we have one more layer of nesting and nested transclusion -- cgit v1.2.3