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

The @ViewChild decorator does not select providers defined through a string token #38313

Closed
zaracooper opened this issue Jul 31, 2020 · 1 comment

Comments

@zaracooper
Copy link
Contributor

@zaracooper zaracooper commented Jul 31, 2020

🐞 bug report

Affected Package

The issue is caused by package @angular/core.

Is this a regression?

Yes. This bug was not present before version 9 when Ivy was enabled by default. With ViewEngine, this bug is not present.

Description

In the documentation for the @ViewChild decorator, one of the accepted selectors is stated as:

Any provider defined through a string token (e.g. @ViewChild('someToken') someTokenVal: any)

However, with Ivy enabled, using this type of selector returns an undefined value. With ViewEngine, it works as described and returns a value.

🔬 Minimal Reproduction

https://stackblitz.com/edit/view-child-string-token-provider-selector

🔥 Exception or Error

No error, @ViewChild just returns an undefined value.

🌍 Your Environment

Angular CLI: 10.0.4
Node: 12.9.0
OS: darwin x64

Angular: 10.0.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.4
@angular-devkit/build-angular     0.1000.4
@angular-devkit/build-optimizer   0.1000.4
@angular-devkit/build-webpack     0.1000.4
@angular-devkit/core              10.0.4
@angular-devkit/schematics        10.0.4
@angular/cli                      10.0.4
@ngtools/webpack                  10.0.4
@schematics/angular               10.0.4
@schematics/update                0.1000.4
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0
@ngbot ngbot bot added this to the needsTriage milestone Jul 31, 2020
@crisbeto crisbeto self-assigned this Aug 1, 2020
crisbeto added a commit to crisbeto/angular that referenced this issue Aug 1, 2020
Queries weren't matching directives that provide themselves via string injection tokens, because the assumption was that any string passed to a query decorator refers to a template reference.

These changes make it so we match both template references and providers while giving precedence to the template references.

Fixes angular#38313.
Fixes angular#38315.
crisbeto added a commit to crisbeto/angular that referenced this issue Aug 1, 2020
Queries weren't matching directives that provide themselves via string
injection tokens, because the assumption was that any string passed to
a query decorator refers to a template reference.

These changes make it so we match both template references and
providers while giving precedence to the template references.

Fixes angular#38313.
Fixes angular#38315.
crisbeto added a commit to crisbeto/angular that referenced this issue Aug 9, 2020
Queries weren't matching directives that provide themselves via string
injection tokens, because the assumption was that any string passed to
a query decorator refers to a template reference.

These changes make it so we match both template references and
providers while giving precedence to the template references.

Fixes angular#38313.
Fixes angular#38315.
AndrewKushnir added a commit that referenced this issue Aug 10, 2020
Queries weren't matching directives that provide themselves via string
injection tokens, because the assumption was that any string passed to
a query decorator refers to a template reference.

These changes make it so we match both template references and
providers while giving precedence to the template references.

Fixes #38313.
Fixes #38315.

PR Close #38321
profanis added a commit to profanis/angular that referenced this issue Sep 5, 2020
Queries weren't matching directives that provide themselves via string
injection tokens, because the assumption was that any string passed to
a query decorator refers to a template reference.

These changes make it so we match both template references and
providers while giving precedence to the template references.

Fixes angular#38313.
Fixes angular#38315.

PR Close angular#38321
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 10, 2020

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 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants