question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

one component in ng-template cannot query by @ViewChild whenever set static true or false in ng8

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

this behavior is only in ng8

Description

one component in ng-template cannot query by @ViewChild whenever set static true or false in ng8

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-j3besy

🔥 Exception or Error

html:

<ng-template>
  <hello name="{{ name }}"></hello>
</ng-template>

ts:
  @ViewChild(HelloComponent, {static: false}) hello: HelloComponent;
  ngOnInit() {
    console.log(this.hello)
  }
  ngAfterViewInit() {
    console.log(this.hello)
  }

🌍 Your Environment

Angular Version:


 _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 8.0.3
Node: 10.16.0
OS: win32 x64
Angular: 8.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.3
@angular-devkit/build-angular     0.800.3
@angular-devkit/build-optimizer   0.800.3
@angular-devkit/build-webpack     0.800.3
@angular-devkit/core              8.0.3
@angular-devkit/schematics        8.0.3
@angular/cli                      8.0.3
@ngtools/webpack                  8.0.3
@schematics/angular               8.0.3
@schematics/update                0.800.3
rxjs                              6.4.0
typescript                        3.4.5
webpack                           4.30.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hpyoucommented, Jun 26, 2019

@mlc-mlapis yes,i got it, thank you

0reactions
angular-automatic-lock-bot[bot]commented, Sep 15, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How should I use the new static option for @ViewChild in ...
In ng8 , you can manually set when to access the child component in the parent component. When you set static to true,...
Read more >
Can't use ViewChild to get Component in ngAfterViewInit() by ...
We have validated your reported query. In Angular, we cannot access the reference of child elements when placed inside the ng-template.
Read more >
@ViewChild static: true or false | Part 29 - YouTube
Angular #mututorial #ViewChildIn this video you will when to use static True & False.
Read more >
ngTemplateOutlet: The secret to customisation - Angular inDepth
ngTemplateOutlet is a powerful tool for creating customisable components. It is used by many Angular libraries to enable users to provide custom templates....
Read more >
Angular: @ViewChild() and @ContentChildren() decorators
The result of the query is dynamic and updated when the DOM changes. Given the following HTML settings-panel.component.html : 1 2 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found