aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/compile.js
diff options
context:
space:
mode:
authorBrian Ford2013-09-25 12:30:51 -0700
committerBrian Ford2013-09-25 17:25:00 -0700
commite0c134b8bfa282379daec6a7137512d58f956443 (patch)
tree7679e2ec7443df3e53820a4637fe9ba1b71126f1 /src/ng/compile.js
parent418d7a36ff1969a4155813863c4d2363ff2f651f (diff)
downloadangular.js-e0c134b8bfa282379daec6a7137512d58f956443.tar.bz2
fix($compile): work around issue in jQuery 1.10.2
jQuery 1.10.2 does not attach data to comment nodes, which previously broke `$compile`. This changes how elements with "transclude element" and a controller are compiled to avoid the issue. Closes #3764
Diffstat (limited to 'src/ng/compile.js')
-rw-r--r--src/ng/compile.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index d97aeaf6..1b251044 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -925,7 +925,14 @@ function $CompileProvider($provide) {
}
optional = optional || value == '?';
}
+
value = $element[retrievalMethod]('$' + require + 'Controller');
+
+ if ($element[0].nodeType == 8 && $element[0].$$controller) { // Transclusion comment node
+ value = value || $element[0].$$controller;
+ $element[0].$$controller = null;
+ }
+
if (!value && !optional) {
throw $compileMinErr('ctreq', "Controller '{0}', required by directive '{1}', can't be found!", require, directiveName);
}
@@ -1040,9 +1047,16 @@ function $CompileProvider($provide) {
}
controllerInstance = $controller(controller, locals);
- $element.data(
- '$' + directive.name + 'Controller',
- controllerInstance);
+
+ // Directives with element transclusion and a controller need to attach controller
+ // to the comment node created by the compiler, but jQuery .data doesn't support
+ // attaching data to comment nodes so instead we set it directly on the element and
+ // remove it after we read it later.
+ if ($element[0].nodeType == 8) { // Transclusion comment node
+ $element[0].$$controller = controllerInstance;
+ } else {
+ $element.data('$' + directive.name + 'Controller', controllerInstance);
+ }
if (directive.controllerAs) {
locals.$scope[directive.controllerAs] = controllerInstance;
}