Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e0c134b

Browse files
committedSep 26, 2013
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
1 parent 418d7a3 commit e0c134b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
 

‎bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "AngularJS",
33
"devDependencies": {
4-
"jquery": "git://github.com/components/jquery.git#v1.8.3",
4+
"jquery": "1.10.2",
55
"lunr.js": "0.4.0",
66
"google-code-prettify": "1.0.0",
77
"components-font-awesome": "3.1.0",

‎src/ng/compile.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,14 @@ function $CompileProvider($provide) {
925925
}
926926
optional = optional || value == '?';
927927
}
928+
928929
value = $element[retrievalMethod]('$' + require + 'Controller');
930+
931+
if ($element[0].nodeType == 8 && $element[0].$$controller) { // Transclusion comment node
932+
value = value || $element[0].$$controller;
933+
$element[0].$$controller = null;
934+
}
935+
929936
if (!value && !optional) {
930937
throw $compileMinErr('ctreq', "Controller '{0}', required by directive '{1}', can't be found!", require, directiveName);
931938
}
@@ -1040,9 +1047,16 @@ function $CompileProvider($provide) {
10401047
}
10411048

10421049
controllerInstance = $controller(controller, locals);
1043-
$element.data(
1044-
'$' + directive.name + 'Controller',
1045-
controllerInstance);
1050+
1051+
// Directives with element transclusion and a controller need to attach controller
1052+
// to the comment node created by the compiler, but jQuery .data doesn't support
1053+
// attaching data to comment nodes so instead we set it directly on the element and
1054+
// remove it after we read it later.
1055+
if ($element[0].nodeType == 8) { // Transclusion comment node
1056+
$element[0].$$controller = controllerInstance;
1057+
} else {
1058+
$element.data('$' + directive.name + 'Controller', controllerInstance);
1059+
}
10461060
if (directive.controllerAs) {
10471061
locals.$scope[directive.controllerAs] = controllerInstance;
10481062
}

1 commit comments

Comments
 (1)

igienger commented on Sep 30, 2013

@igienger

Hey -- I think this breaks:
angular.element(transcludeEl).controller('directiveName')

I think JQLiteController must be updated as well?
https://github.com/angular/angular.js/blob/master/src/jqLite.js#L325

This repository has been archived.