Can't require a parent directive of an element with the same directive.
Just as the ngForm directive is able to be nested and communicate with parent ngForm controllers, there should be a clear method to optionally require a parent directive in the case where the current element contains the same directive. Currently, a require value of ^?myDir will result in the current controller being injected into the link function of the myDir directive. It would be very helpful if a require value such as ^^?myDir would ignore the current element/controller and use the same methodology used in the ngForm directive, effectively: element.parent().controller( 'myDir' );.
repro -- It appears that require: '^' for same attribute will inject attributes own controller. This could be a problem for creating tree structures with the same directive. I'm not sure this is really a desirable behaviour and will look into it
It seems to be due to jqLite's implementation of inheritedData(), which will use the current node's data if there is any with the correct name. This is probably desirable for most uses of inheritedData(), but not necessarily this one.
I have yet to run into anyone who has done ^myDir and wanted it to match on the current element. If it were up to me I'd just make the default behavior of ^myDir search exclusively starting from the parent node. This is consistent with what the current documentation says and would avoid adding extra ^^myDir syntaxes.
I tend to agree, but I think it should wait for some proper review, as there may be some use case that I'm oblivious to that depends on this behaviour (as unlikely as that may be)
I tend to agree with Daniel on this, however I have seen 3rd party documentation written like: http://www.cheatography.com/proloser/cheat-sheets/angularjs/
Where it says ^ means "Look on parent elements too"
Yeh, I've also got use-cases where it would be desirable to omit controllers on the same elements. If there are concerns about breaking changes we could have alternative syntax that would allow us to explicitly say that we want only controllers from a parent element (maybe ^^?).
It would be nice to get this fixed. IMO it should start with the parent. All the documentation states that '^' refers to parents.
Yes, it would be, in the mean time you can get the parent controller like this. This hack seems pretty stable.
var cntrl = element.parent().inheritedData('$YOURCNTRLNAMEController')
where YOURCNTRLNAME is whatever you named your controller.
On Thu, Jul 17, 2014 at 9:38 AM, Andrew Collard [email protected] wrote:
It would be nice to get this fixed. IMO it should start with the parent. All the documentation states that '^' refers to parents.
— Reply to this email directly or view it on GitHub https://github.com/angular/angular.js/issues/4518#issuecomment-49331765.
+1 this would be nice! Thanks for the workaround in the meantime..