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

Commit

Permalink
fix($compile): work around issue in jQuery 1.10.2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
btford committed Sep 26, 2013
1 parent 418d7a3 commit e0c134b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "AngularJS",
"devDependencies": {
"jquery": "git://github.com/components/jquery.git#v1.8.3",
"jquery": "1.10.2",
"lunr.js": "0.4.0",
"google-code-prettify": "1.0.0",
"components-font-awesome": "3.1.0",
Expand Down
20 changes: 17 additions & 3 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down

1 comment on commit e0c134b

@igienger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.