From 5c560117425e7b3f7270389274476e843d6f69ec Mon Sep 17 00:00:00 2001 From: jankuca Date: Thu, 8 Aug 2013 16:04:11 -0700 Subject: fix($compile): always instantiate controllers before pre-link fns run Controllers should be always instantiated after compile fn runs, but before pre-link fn runs. This way, controllers are available to pre-link fns that request them. Previously this was broken for async directives (directives with templateUrl). Closes #3493 Closes #3482 Closes #3514 --- src/ng/compile.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ng/compile.js b/src/ng/compile.js index 25d48313..39d3338f 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -782,13 +782,6 @@ 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; @@ -877,6 +870,13 @@ 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); @@ -1157,7 +1157,7 @@ function $CompileProvider($provide) { origAsyncDirective = directives.shift(), // The fact that we have to copy and patch the directive seems wrong! derivedSyncDirective = extend({}, origAsyncDirective, { - controller: null, templateUrl: null, transclude: null, scope: null, replace: null + templateUrl: null, transclude: null, scope: null, replace: null }), templateUrl = (isFunction(origAsyncDirective.templateUrl)) ? origAsyncDirective.templateUrl($compileNode, tAttrs) -- cgit v1.2.3