diff options
| -rw-r--r-- | src/ng/compile.js | 23 | ||||
| -rwxr-xr-x | test/ng/compileSpec.js | 55 | 
2 files changed, 67 insertions, 11 deletions
| diff --git a/src/ng/compile.js b/src/ng/compile.js index dbecd3b1..9e124edb 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -621,6 +621,13 @@ function $CompileProvider($provide) {          directiveName = directive.name; +        if (directiveValue = directive.controller) { +          controllerDirectives = controllerDirectives || {}; +          assertNoDuplicate("'" + directiveName + "' controller", +              controllerDirectives[directiveName], directive, $compileNode); +          controllerDirectives[directiveName] = directive; +        } +          if (directiveValue = directive.transclude) {            assertNoDuplicate('transclusion', transcludeDirective, directive, $compileNode);            transcludeDirective = directive; @@ -698,13 +705,6 @@ function $CompileProvider($provide) {            }          } -        if (!directive.templateUrl && directive.controller) { -          controllerDirectives = controllerDirectives || {}; -          assertNoDuplicate("'" + directiveName + "' controller", -              controllerDirectives[directiveName], directive, $compileNode); -          controllerDirectives[directiveName] = directive; -        } -          if (directive.terminal) {            nodeLinkFn.terminal = true;            terminalPriority = Math.max(terminalPriority, directive.priority); @@ -962,7 +962,7 @@ function $CompileProvider($provide) {            origAsyncDirective = directives.shift(),            // The fact that we have to copy and patch the directive seems wrong!            derivedSyncDirective = extend({}, origAsyncDirective, { -            templateUrl: null, transclude: null, scope: null +            controller: null, templateUrl: null, transclude: null, scope: null            });        $compileNode.html(''); @@ -1008,9 +1008,10 @@ function $CompileProvider($provide) {                replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);              } -            afterTemplateNodeLinkFn(function() { -              beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller); -            }, scope, linkNode, $rootElement, controller); +            afterTemplateNodeLinkFn( +              beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller), +              scope, linkNode, $rootElement, controller +            );            }            linkQueue = null;          }). diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 93fe6ced..c998cda8 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2258,6 +2258,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: '<p>Hello</p>', +            controller: Ctrl +          }; +        }); +      }); + +      inject(function ($templateCache, $compile, $rootScope, log) { +        $rootScope.foo = "bar"; + +        element = $compile('<div my-directive my-foo="foo"></div>')($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', '<p>Hello</p>'); +        $rootScope.foo = "bar"; + +        element = $compile('<div my-directive my-foo="foo"></div>')($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 | 
