This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Directive unable to get parent controller if it is the same directive type #8240
Closed
Description
When nesting the same directive it is not possible to get the parent directives controller.
<concat>
<concat>
</concat>
</concat>
testApp.directive('concat', function () {
return {
require: ['concat', '?^concat'],
controller: function () {},
link: function (scope, elem, attrs, cntrls) {
var cntrl = cntrls[0];
var parent = cntrls[1];
// (parent === cntrl) = true
}
};
});
Here is a full JSFiddle: http://jsfiddle.net/R2Ycd/2/
The issue is in the following line in getControllers function in compile.js.
value = value || $element[retrievalMethod]('$' + require + 'Controller');
The inheritedData retrieval method will look locally first. It should start with the parent first since '^' was specified.
if(retrievalMethod == 'inheritedData'){
var parent = $element.parent();
if(parent)
value = parent[retrievalMethod]('$' + require + 'Controller');
}
else
value = value || $element[retrievalMethod]('$' + require + 'Controller');