fix($compile): use correct parent element when requiring on html element
Fixes #16535 Closes #16647
This commit is contained in:
+8
-1
@@ -2960,7 +2960,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
|
||||
if (!value) {
|
||||
var dataName = '$' + name + 'Controller';
|
||||
value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);
|
||||
|
||||
if (inheritType === '^^' && $element[0] && $element[0].nodeType === NODE_TYPE_DOCUMENT) {
|
||||
// inheritedData() uses the documentElement when it finds the document, so we would
|
||||
// require from the element itself.
|
||||
value = null;
|
||||
} else {
|
||||
value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!value && !optional) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html ng-app="test" require-directive require-target-directive>
|
||||
<body>
|
||||
<div id="container"></div>
|
||||
<script src="angular.js"></script>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
angular.
|
||||
module('test', []).
|
||||
provider('$exceptionHandler', /** @this */ function() {
|
||||
this.$get = [function() {
|
||||
return function(error) {
|
||||
window.document.querySelector('#container').textContent = error && error.message;
|
||||
};
|
||||
}];
|
||||
}).
|
||||
|
||||
directive('requireDirective', function() {
|
||||
return {
|
||||
require: '^^requireTargetDirective',
|
||||
link: function(scope, element, attrs, ctrl) {
|
||||
window.document.querySelector('#container').textContent = ctrl.content;
|
||||
}
|
||||
};
|
||||
}).
|
||||
directive('requireTargetDirective', function() {
|
||||
return {
|
||||
controller: function() {
|
||||
this.content = 'requiredContent';
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
describe('require parent controller on html element', function() {
|
||||
it('should not use the html element as the parent element', function() {
|
||||
|
||||
loadFixture('directive-require-html');
|
||||
|
||||
expect(element(by.id('container')).getText()).toContain('Controller \'requireTargetDirective\', required by directive \'requireDirective\', can\'t be found!');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user