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

Commit 396071a

Browse files
committed
fix($compile): use correct parent element when requiring on html element
1 parent a42f8a0 commit 396071a

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/ng/compile.js

+8-1
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].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) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html ng-app="test" require-directive parent-directive>
3+
<body>
4+
<script src="angular.js"></script>
5+
<script src="script.js"></script>
6+
</body>
7+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
angular.
4+
module('test', []).
5+
directive('requireDirective', function() {
6+
return {
7+
require: '^^parentDirective',
8+
link: function() {}
9+
};
10+
}).
11+
directive('parentDirective', function() {
12+
return {
13+
controller: function() {}
14+
};
15+
});
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
browser.manage().logs().get('browser').then(function(browserLogs) {
9+
expect(browserLogs[0].level.value).toBe(1000);
10+
expect(browserLogs[0].message).toContain('Controller \'parentDirective\', required by directive \'requireDirective\', can\'t be found!');
11+
});
12+
});
13+
});

0 commit comments

Comments
 (0)