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

Commit 05ac702

Browse files
committed
fix($compile): use correct parent element when requiring on html element
Fixes #16535 Closes #16647
1 parent 6882113 commit 05ac702

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

src/ng/compile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2960,7 +2960,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
29602960

29612961
if (!value) {
29622962
var dataName = '$' + name + 'Controller';
2963-
value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);
2963+
2964+
if (inheritType === '^^' && $element[0] && $element[0].nodeType === NODE_TYPE_DOCUMENT) {
2965+
// inheritedData() uses the documentElement when it finds the document, so we would
2966+
// require from the element itself.
2967+
value = null;
2968+
} else {
2969+
value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);
2970+
}
29642971
}
29652972

29662973
if (!value && !optional) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html ng-app="test" require-directive require-target-directive>
3+
<body>
4+
<div id="container"></div>
5+
<script src="angular.js"></script>
6+
<script src="script.js"></script>
7+
</body>
8+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
angular.
4+
module('test', []).
5+
provider('$exceptionHandler', /** @this */ function() {
6+
this.$get = [function() {
7+
return function(error) {
8+
window.document.querySelector('#container').textContent = error && error.message;
9+
};
10+
}];
11+
}).
12+
13+
directive('requireDirective', function() {
14+
return {
15+
require: '^^requireTargetDirective',
16+
link: function(scope, element, attrs, ctrl) {
17+
window.document.querySelector('#container').textContent = ctrl.content;
18+
}
19+
};
20+
}).
21+
directive('requireTargetDirective', function() {
22+
return {
23+
controller: function() {
24+
this.content = 'requiredContent';
25+
}
26+
};
27+
});
28+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
describe('require parent controller on html element', function() {
4+
it('should not use the html element as the parent element', function() {
5+
6+
loadFixture('directive-require-html');
7+
8+
expect(element(by.id('container')).getText()).toContain('Controller \'requireTargetDirective\', required by directive \'requireDirective\', can\'t be found!');
9+
});
10+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy