ViewChildren's QueryList.changes doesn't detect changes
See original GitHub issueI’m submitting a …
[x ] bug report
[ ] feature request
[ ] support request
Current behavior When subscribing to QueryList.changes created by a ViewChild, any changes to bound variables are not detected.
Expected behavior
- Template to be updated
- If this is WAI, the debug change detector should detect that a bound variable was changed and throw, similar to updating bound variables in ngAfterViewChecked.
Minimal reproduction of the problem with instructions Plunker
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
QueryList changes subscribe does not work - Stack Overflow
I am adding dynamically other components, that will be present in the QueryList , but if I subscribe to the changes of the...
Read more >QueryList changes event not triggered by changes in children.
We are setting @ViewChild / @ViewChildren and pushing changes to it right after the component has been created, i.e. before ngInit . This...
Read more >Angular - Understanding How To Use QueryList Properly.
Any time a child element is added, removed, or moved, the query list will be updated, and the changes observable in the query...
Read more >QueryList - Angular
Updates the stored data of the query list, and resets the dirty flag to false , so that on change detection, it will...
Read more >Understanding ViewChildren, ContentChildren, and QueryList ...
changes () — Changes can be observed by subscribing to the changes Observable. Any time a child element is added, removed, or moved,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am experiencing similar problems. Sounds pretty serious to me (and similar to #10962 ?)
Real case scenario for me:
When the template gets projected at any time with
createEmbeddedView(...), the@ViewChildren(Tab)query that I have at TabsPanel does not get notified with the new tab.Sure!
Expected: Clicking the “Populate!” button adds a child component Foo, gated by an *ngIf directive. A ViewChildren-generated QueryList.changes observable is subscribed to that should add a message to the template an array when an event arrives. The message says “A ‘<foo>’ element was added”
Actual: When the button is clicked, the Foo component appears. The .changes event is fired, and the message is added to the template. However, the change detection is not run, causing a disconnect between the model and the template. The disconnect can be rectified by clicking the other button to force change detection via ChangeDetectorRef.markForCheck. No warning message about changing after it was checked is shown.
Desired: Any other observable I’ve ever used that changes the template in the .subscribe function correctly causes change detection to occur. A QueryList generated via ContentChildren works just fine (new plunker), so I suspect this has to do with the timing of the ViewChildren’s query firing after content checking as opposed to in a new microTask.