Skip to content
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
@acollard

Description

@acollard

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');

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions