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

[bug] RC.2 breaks @ViewChild to component thru forwardRef (recursive component structures) #9459

Closed
KiaraGrouwstra opened this issue Jun 22, 2016 · 7 comments

Comments

@KiaraGrouwstra
Copy link
Contributor

After this commit from RC2 ("set fixed @ViewChild / @ContentChild right after the view is created"), my @ViewChilds started breaking, erroring with:
Can't construct a query for the property <viewChildName> of <componentName> since the query selector wasn't defined.

Since I'm using recursive component structures, I have to use forwardRef to include the child components as directives into the host component. So what I have is like this:

@Component({
  directives: [ forwardRef(() => ChildComp) ]
})
class HostComp {
  @ViewChild(ChildComp) child: ChildComp;
}

The undefined selector here is the ChildComp argument of @ViewChild(ChildComp). If this forwardRef is not yet resolved here at the moment it's interpreting the ViewChild since RC2, then I guess it makes sense that it's coming up with an undefined selector.

I've yet to verify that with a minimal reproduction though. Plunker forthcoming -- I may need to await until my recent PR lands into the next RC. Anyway, posting this already in case anyone else has come across this error as well.

@ericmartinezr
Copy link
Contributor

The error you're seeing comes from this fix #9018 for this issue #4489

@KiaraGrouwstra
Copy link
Contributor Author

Thanks, that does look even more relevant.

@pkozlowski-opensource
Copy link
Member

@tycho01 could you please share a minimal plunker (please use RC.3)? I'm surprised that it used to work, would like to confirm.

@vicb
Copy link
Contributor

vicb commented Jun 22, 2016

Would that work ?

class HostComp {
  @ViewChild(forwardRef(() => ChildComp)) child: ChildComp;

@pkozlowski-opensource
Copy link
Member

Yep, forwardRef will work, so we've got an easy work-around: https://plnkr.co/edit/sbQ1lKL9YexoFVfYa7Cp?p=preview

I'm still very much surprised it used to work without forwardRef....

@KiaraGrouwstra
Copy link
Contributor Author

KiaraGrouwstra commented Jun 22, 2016

Yeah, that seems to be helping. Thanks for the quick suggestions guys.

@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 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants