A runtime error is thrown when calling `detectChanges` inside the `transform` method of a pipe.
See original GitHub issueš bug report
Affected Package
The issue is caused by package @angular/core
.
Is this a regression?
Description
A runtime error is thrown when calling detectChanges
inside the transform
method of a pipe.
š¬ Minimal Reproduction
A reproduction of this issue can be found here.
š„ Exception or Error
core.js:4200 ERROR TypeError: Cannot read property 'call' of undefined
at callHook (core.js:3045)
at callHooks (core.js:3008)
at executeCheckHooks (core.js:2941)
at selectIndexInternal (core.js:6177)
at Module.ɵɵadvance (core.js:6156)
at AppComponent_Template (app.component.html:1)
at executeTemplate (core.js:7306)
at refreshView (core.js:7175)
at refreshComponent (core.js:8329)
at refreshChildComponents (core.js:6968)
š Your Environment
Angular Version:
Angular CLI: 10.0.7
Node: 12.18.3
OS: darwin x64
Angular: 10.0.12
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.7
@angular-devkit/build-angular 0.1000.7
@angular-devkit/build-optimizer 0.1000.7
@angular-devkit/build-webpack 0.1000.7
@angular-devkit/core 10.0.7
@angular-devkit/schematics 10.0.7
@angular/cdk 10.1.3
@angular/cli 10.0.7
@angular/material 10.1.3
@ngtools/webpack 10.0.7
@schematics/angular 10.0.7
@schematics/update 0.1000.7
rxjs 6.5.5
typescript 3.9.7
webpack 4.43.0
Anything else relevant?
This issue only happens when Ivy is enabled.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Attempt to use a destroyed view: detectChanges
The issue clearly comes from detectChanges() because the changes were done and the method called during the destroy phase of the component.
Read more >NG0100: Expression has changed after it was checked
Angular throws an ExpressionChangedAfterItHasBeenCheckedError when an expression value has been changed after change detection has completed. Angular onlyĀ ...
Read more >fixture.detectchanges() throws error
As described in the Angular testing tutorial, the component isn't initialized fully until you call fixture.detectChanges() the first time.
Read more >Testing Pipes ā Testing Angular
An Angular Pipe is a special function that is called from a Component ... In essence, a Pipe is class with a public...
Read more >Guide on Unit testing in Angular and NgRx using Jasmine
Pipe Testing. A pipe is the easiest portion of an application to test because its class usually only contains one method called transform()...
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 FreeTop 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
Top GitHub Comments
I spent some more time on it and I found a couple of solutions, but they ended up breaking other functionality so I think Iāll leave this for somebody that knows the hook logic better. Hereās what Iāve got so far:
ViewContainerRef.detectChanges
is called at the wrong time. The issue can be reproduced by calling it inside an input setter of a directive that hasngAfterViewInit
andngOnChanges
hooks. Hereās an even simpler test case:refreshView
in the middle of it running the init hooks. In this particular case, it breaks when itās trying to runngAfterViewInit
, but the same problem can be observed if we change it tongAfterContentInit
,ngAfterViewChecked
orngAfterContentChecked
.LView
state into the global store (see https://github.com/angular/angular/commit/e16f75db566e7bb22d8b8c1566f8ed5be6874be0). I suspect that we may have to do the same forLView[FLAGS]
, but I donāt know what the side-effects of doing so would be.Iāve been looking into it. It seems to happen if there is an init hook, an
ngOnChanges
hook and a binding with a pipe on the same element. Hereās a simplified test.Iāll try to either resolve it or post my findings here.