Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewChildren and ViewChild are searching for child / children only #11039

Closed
AlmogShaul opened this issue Aug 24, 2016 · 11 comments
Closed

ViewChildren and ViewChild are searching for child / children only #11039

AlmogShaul opened this issue Aug 24, 2016 · 11 comments

Comments

@AlmogShaul
Copy link
Contributor

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
ViewChildren and ViewChild are searching for child / children only,

Expected/desired behavior
They should search for descendents also.

Reproduction of the problem
steps for reproduce:
Lets say you have component1 that declare component2 inside of it,
and component2 declare component3 inside of itself.
component1 can't use ViewChildren to get component3.

What is the expected behavior?
I would expect component1 to find component3

What is the motivation / use case for changing the behavior?
I want to find descendents of specific type and not only children

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser: [Chrome 52]
  • Language: [ TypeScript 1.8]
@michaelchiche
Copy link
Contributor

michaelchiche commented Aug 24, 2016

@ViewChildren(ExampleComponent, {descendants: true}) examples: QueryList<ExampleComponent>;

@AlmogShaul
Copy link
Contributor Author

@michaelchiche
The interface is:

export interface ViewChildrenMetadataFactory {
(selector: Type|Function|string, {read}?: {read?: any}): any;
new (selector: Type|Function|string, {read}?: {read?: any}): ViewChildrenMetadata;
}

@michaelchiche
Copy link
Contributor

michaelchiche commented Aug 24, 2016

Sorry, got confused with ContentChildren.
Well instead of doig that, since its a viewChild(ren).
You can set component2 as a viewchild of component1.
And then component3 as a viewchild of component2 so that now you can access the viewchild from component1 throught component2

@AlmogShaul
Copy link
Contributor Author

@michaelchiche
Is there a reason not to support it? maybe I would open a pull request for it?

@AlmogShaul
Copy link
Contributor Author

export class ViewChildrenMetadata extends ViewQueryMetadata {
constructor(_selector: Type|string, {read = null}: {read?: any} = {}) {
super(_selector, {descendants: true, read: read});
}
toString(): string { return @ViewChildren(${stringify(this.selector)}); }
}
I see that it passes its super {descendants: true, read: read}
so it should work.
It doesn't
maybe the descendants parameter is for something else?

@ericmartinezr
Copy link
Contributor

Probably related (note the "probably") #5241 (comment)

@AlmogShaul
Copy link
Contributor Author

It is the same issue.
Although I think we should have some mechanism to query all components of specific type.

@vicb
Copy link
Contributor

vicb commented Aug 25, 2016

duplicate

@vicb vicb closed this as completed Aug 25, 2016
@geoff-mci
Copy link

This issue was for @ViewChildren, the linked issue was for @ContentChildren resolution of the linked issue was:
@ContentChildren(..., {descendants: true})
can we also use:
@ViewChildren(..., {descendants: true})
?

(my use case is to find all the elements that have a 'scroll-on-click' directive on them so I can auto scroll the form to ensure focussed fields are not obscured)

@bibhas2
Copy link

bibhas2 commented Dec 21, 2018

What is this duplicate of? Google search on this topic shows this issue only.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants