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

feat($compile): optionally get controllers from ancestors only #4540

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Oct 20, 2013

Implement option to strengthen require '^' operator, by adding another '^'.

When a second '^' is used, the controller will only search parent nodes for the matching controller, and will throw or return null if not found, depending on whether or not the requirement is optional.


It might be good to simply make this strengthened behaviour the default, since given what the original docs were saying, it really is the expected behaviour.

Closes #4518

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

Sorry, something went wrong.

@caitp
Copy link
Contributor Author

caitp commented Oct 26, 2013

CLA signed previously as Caitlin Potter

@cphillips
Copy link

Thanks Caitlin, I ran into this problem over the weekend.

@dtabuenc
Copy link
Contributor

dtabuenc commented Dec 2, 2013

Any word on getting this merged in?

@IgorMinar
Copy link
Contributor

I'm sorry, but I wasn't able to verify your CLA signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let me know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@dtabuenc
Copy link
Contributor

dtabuenc commented Dec 7, 2013

That's strange since she has other commits merged in to 1.2.4

@caitp
Copy link
Contributor Author

caitp commented Dec 7, 2013

I think that's an automated script doing that, @dtabuenc (I can't be sure, but since my inbox was full of those messages this morning, I have to assume). It's probably being worked on

@IgorMinar
Copy link
Contributor

CLA signature verified! Thank you!

Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes).

@caitp
Copy link
Contributor Author

caitp commented Sep 5, 2014

PTAL --- rebased since this got mentioned in #8511 again

@caitp caitp modified the milestones: 1.3.0-rc.2, Backlog Sep 5, 2014
@jeffbcross
Copy link
Contributor

Has @IgorMinar or @tbosch given their blessing of the API change?

@caitp
Copy link
Contributor Author

caitp commented Sep 9, 2014

It hasn't really come up, I almost forgot I had this patch open since it's been here so long

@IgorMinar
Copy link
Contributor

why schedule this for rc2 now?

I'd like a really convincing argument, especially a solid use case. otherwise we should move this back to backlog.

@caitp
Copy link
Contributor Author

caitp commented Sep 9, 2014

Compelling use-case: recursive trees of directives (obviously there's a bit more involved, but this is one of the annoying things to hack around when it comes to component recursion).

Alternative reasons: people think "^" means parent element, when really it means "the current element or any parent element".

@@ -1564,14 +1566,20 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {


function getControllers(directiveName, require, $element, elementControllers) {
var value, retrievalMethod = 'data', optional = false;
var value, retrievalMethod = 'data', optional = false, search = $element, prematch, match;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search => $searchElement

@cphillips
Copy link

My use case was nested directives, as in

In my implementation of the directive I wanted the access the parent
controller, and not my own controller ^ ends up finding 'my own'
controller, if you will, and not the parent controller.

On Tue, Sep 9, 2014 at 10:19 AM, Igor Minar notifications@github.com
wrote:

why schedule this for rc2 now?

I'd like a really convincing argument, especially a solid use case.
otherwise we should move this back to backlog.


Reply to this email directly or view it on GitHub
#4540 (comment).

ALL_OR_NOTHING_ATTRS = makeMap('ngSrc,ngSrcset,src,srcset');
ALL_OR_NOTHING_ATTRS = makeMap('ngSrc,ngSrcset,src,srcset'),
REQUIRE_PREFIX_REGEXP = /(\?)|(\^\^?)/g,
REQUIRE_PREFIX_PRE_REGEXP = /^((\?)|(\^\^?))+/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to regexps?

why not just /^((\^)(\^)?(\?)?)?/ and then check which groups matched?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that will remove one of the regexps as well as the loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't that impose a requirement that ^ comes before ? if people want to do both? I thought about doing it that way but it just seems fragile usability-wise

@IgorMinar
Copy link
Contributor

suggested some change + we need docs update. otherwise lgtm

match = require.match(REQUIRE_PREFIX_REGEXP);
require = require.substring(match[0].length);

if (match[3]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the requested changes, except added a way to ask for optional before specifying the search root. I think it's a lot more code this way actually.

@tbosch
Copy link
Contributor

tbosch commented Sep 22, 2014

@caitp Could you add the changes to the docs as well?

@caitp
Copy link
Contributor Author

caitp commented Sep 22, 2014

yes, one moment

Implement option to strengthen require '^' operator, by adding another '^'.

When a second '^' is used, the controller will only search parent nodes for the
matching controller, and will throw or return null if not found, depending on
whether or not the requirement is optional.

Closes angular#4518
@caitp
Copy link
Contributor Author

caitp commented Sep 22, 2014

updated

@jeffbcross jeffbcross modified the milestones: 1.3.0-rc.3, 1.3.0-rc.4 Sep 23, 2014
@caitp caitp closed this in 07e3abc Sep 26, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't require a parent directive of an element with the same directive.
8 participants