angular: bug(pipes): cannot read property 'constructor' of undefined

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 12
  • Comments: 37 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@jeffbcross I’ve noticed this issue whenever I route to a view that contains a pipe but no data gets passed into that pipe before I navigate away (i.e. the async pipe but the observable doesn’t get instantiated before the user navigates away). It’s probably the same thing you’re running into.

I have a same issue with ng2-translate, and the workaround works for me

ngOnInit(){ this.initialized=true; }

<p *ngIf="initialized">{{ 'to.be.translated' | translate }}</p>

I’m seeing this error in beta 14. My component is using routing to check OnActivate if a user prop on a service is undefined, if yes redirect to Login, else show results of in a table.

I refactored my property (which was working) from myBizObjects: BizObject[] to myBizObjects: Observable<BizObject[]>

Then added the async pipe to my ngFor in the template and got the mentioned exception:

angular2.dev.js:23941 Error: Uncaught (in promise): TypeError: Cannot read property ‘constructor’ of undefined

I’ll go back to my original implementation, calling subscribe from within the component and using a non-Observable array for the time being.

I’m using pipes and this error occurred after several arrays go through the pipe, but it is not consistent. Sometimes the error appear after one, two or more clicks (each click will make a new/old array goes through the pipe). I’m not sure whether this is related with this bug, but this is the trace (I’m using angular 2 beta 13):

angular2.dev.js:23877 TypeError: Cannot read property ‘constructor’ of undefined at Object.implementsOnDestroy (angular2.dev.js:5027) at Function.ChangeDetectionUtil.callPipeOnDestroy (angular2.dev.js:8188) at AbstractChangeDetector.ChangeDetector_NextProblemsComponent_1.dehydrateDirectives (viewFactory_NextProblemsComponent:3009) at AbstractChangeDetector.dehydrate (angular2.dev.js:9629) at AbstractChangeDetector.destroyRecursive (angular2.dev.js:9642) at AppView.destroy (angular2.dev.js:10151) at AppViewManager_.destroyViewInContainer (angular2.dev.js:6643) at ViewContainerRef_.remove (angular2.dev.js:6139) at NgFor._bulkRemove (angular2.dev.js:15056) at NgFor._applyChanges (angular2.dev.js:15021)

This bug is a blocker for migrating to Angular 2 for me.

I’m also encountering this issue on upgrading to Angular 2 beta.13.

For me it happens when I attempt a login redirect, using router.navigateByUrl in a custom RouterOutlet. The following errors are being thrown during the destruction of the previous component.

angular2.dev.js:23877 Error: Uncaught (in promise): TypeError: Cannot read property 'constructor' of undefined
    at resolvePromise (zone.js:520)
    at zone.js:497
    at ZoneDelegate.invoke (zone.js:308)
    at Object.NgZoneImpl.inner.inner.fork.onInvoke (angular2.dev.js:2111)
    at ZoneDelegate.invoke (zone.js:307)
    at Zone.run (zone.js:201)
    at zone.js:553
    at ZoneDelegate.invokeTask (zone.js:341)
    at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (angular2.dev.js:2103)
    at ZoneDelegate.invokeTask (zone.js:340)BrowserDomAdapter.logError @ angular2.dev.js:23877ExceptionHandler.call @ angular2.dev.js:1320(anonymous function) @ angular2.dev.js:12763schedulerFn @ angular2.dev.js:13167SafeSubscriber.__tryOrUnsub @ Rx.js:10775SafeSubscriber.next @ Rx.js:10730Subscriber._next @ Rx.js:10690Subscriber.next @ Rx.js:10667Subject._finalNext @ Rx.js:11191Subject._next @ Rx.js:11183Subject.next @ Rx.js:11142EventEmitter.emit @ angular2.dev.js:13148NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ angular2.dev.js:13566NgZoneImpl.inner.inner.fork.onHandleError @ angular2.dev.js:2128ZoneDelegate.handleError @ zone.js:312Zone.runGuarded @ zone.js:218drainMicroTaskQueue @ zone.js:472ZoneTask.invoke @ zone.js:411
zone.js:446 
Unhandled Promise rejection: Cannot read property 'constructor' of undefined ; Zone: angular ; Task: Promise.then ; Value: TypeError: Cannot read property 'constructor' of undefined
    at Object.implementsOnDestroy (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:5027:16)
    at Function.ChangeDetectionUtil.callPipeOnDestroy (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:8188:38)
    at AbstractChangeDetector.ChangeDetector_MainHeader_0.dehydrateDirectives (viewFactory_MainHeader:208:31)
    at AbstractChangeDetector.dehydrate (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:9629:12)
    at AbstractChangeDetector.destroyRecursive (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:9642:12)
    at AbstractChangeDetector.destroyRecursive (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:9649:21)
    at AbstractChangeDetector.destroyRecursive (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:9649:21)
    at AppView.destroy (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:10151:27)
    at AppViewManager_.destroyViewInContainer (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:6643:12)
    at ViewContainerRef_.remove (http://localhost:9000/node_modules/angular2/bundles/angular2.dev.js:6139:17)

Importantly I do not have any pipes, async or otherwise, in the components in question.

[UPDATE] Adding a completely unused and unneeded async pipe to the template of the component being destroyed resolve the issue. This makes no sense and is rather annoying, I assume this is an angular bug.

Still issue persists in angular2 beta 12

image

I am getting this error while changing routes. If i change routes continuously(within a sec) from one url to someother routes. this error exists in server.

try this link

` EXCEPTION: TypeError: Cannot read property ‘constructor’ of undefined vendor.bundle.js:13 EXCEPTION: TypeError: Cannot read property ‘constructor’ of undefinedt.logError @ vendor.bundle.js:13 vendor.bundle.js:13 STACKTRACE:t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 TypeError: Cannot read property ‘constructor’ of undefined at Object.n as implementsOnDestroy at Function.e.callPipeOnDestroy (http://sparkling-development.surge.sh/vendor.bundle.js:5:813) at e.ChangeDetector_e_0.dehydrateDirectives (eval at <anonymous> (http://sparkling-development.surge.sh/vendor.bundle.js:5:28498), <anonymous>:86:49) at e.dehydrate (http://sparkling-development.surge.sh/vendor.bundle.js:5:16985) at e.dehydrateView (http://sparkling-development.surge.sh/vendor.bundle.js:9:9535) at t._viewDehydrateRecurse (http://sparkling-development.surge.sh/vendor.bundle.js:9:4435) at t._destroyViewInContainer (http://sparkling-development.surge.sh/vendor.bundle.js:9:4117) at t.destroyViewInContainer (http://sparkling-development.surge.sh/vendor.bundle.js:9:2867) at t.remove (http://sparkling-development.surge.sh/vendor.bundle.js:9:15132) at t.u as _dispose

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at e.deactivate (http://sparkling-development.surge.sh/vendor.bundle.js:18:21180) at http://sparkling-development.surge.sh/vendor.bundle.js:17:17925 at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:35:1996) at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:7:10567) at http://sparkling-development.surge.sh/vendor.bundle.js:35:1720

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at t.e.deactivate (http://sparkling-development.surge.sh/vendor.bundle.js:17:17891) at t.e.deactivate (http://sparkling-development.surge.sh/vendor.bundle.js:17:17844) at t.e.commit (http://sparkling-development.surge.sh/vendor.bundle.js:17:17100) at t.commit (http://sparkling-development.surge.sh/vendor.bundle.js:17:19201) at http://sparkling-development.surge.sh/vendor.bundle.js:17:15537

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at http://sparkling-development.surge.sh/vendor.bundle.js:17:15509 at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:35:1996) at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:7:10567) at http://sparkling-development.surge.sh/vendor.bundle.js:35:1720 at x (http://sparkling-development.surge.sh/vendor.bundle.js:42:2126)

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at t.e._navigate (http://sparkling-development.surge.sh/vendor.bundle.js:17:15457) at http://sparkling-development.surge.sh/vendor.bundle.js:17:15266 at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:35:1996) at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:7:10567) at http://sparkling-development.surge.sh/vendor.bundle.js:35:1720

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at t.e.navigateByInstruction (http://sparkling-development.surge.sh/vendor.bundle.js:17:15187) at e.onClick (http://sparkling-development.surge.sh/vendor.bundle.js:18:23684) at e.ChangeDetector_e_0.handleEventInternal (eval at <anonymous> (http://sparkling-development.surge.sh/vendor.bundle.js:5:28498), <anonymous>:1795:41) at e.handleEvent (http://sparkling-development.surge.sh/vendor.bundle.js:5:15438) at e.dispatchEvent (http://sparkling-development.surge.sh/vendor.bundle.js:8:2859)

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at e._createInnerZone (http://sparkling-development.surge.sh/vendor.bundle.js:7:10356) at new e (http://sparkling-development.surge.sh/vendor.bundle.js:7:7864) at i (http://sparkling-development.surge.sh/vendor.bundle.js:7:1237) at t.application (http://sparkling-development.surge.sh/vendor.bundle.js:7:2780) at Object.r as bootstrap at Object.webpackJsonp.0 (http://sparkling-development.surge.sh/bundle.js:1:125) at t (http://sparkling-development.surge.sh/vendor.bundle.js:1:107) at window.webpackJsonp (http://sparkling-development.surge.sh/vendor.bundle.js:1:384)t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 EXCEPTION: TypeError: Cannot read property ‘constructor’ of undefined vendor.bundle.js:13 EXCEPTION: TypeError: Cannot read property ‘constructor’ of undefinedt.logError @ vendor.bundle.js:13 vendor.bundle.js:13 STACKTRACE:t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 TypeError: Cannot read property ‘constructor’ of undefined at Object.n as implementsOnDestroy at Function.e.callPipeOnDestroy (http://sparkling-development.surge.sh/vendor.bundle.js:5:813) at e.ChangeDetector_e_0.dehydrateDirectives (eval at <anonymous> (http://sparkling-development.surge.sh/vendor.bundle.js:5:28498), <anonymous>:86:49) at e.dehydrate (http://sparkling-development.surge.sh/vendor.bundle.js:5:16985) at e.dehydrateView (http://sparkling-development.surge.sh/vendor.bundle.js:9:9535) at t._viewDehydrateRecurse (http://sparkling-development.surge.sh/vendor.bundle.js:9:4435) at t._destroyViewInContainer (http://sparkling-development.surge.sh/vendor.bundle.js:9:4117) at t.destroyViewInContainer (http://sparkling-development.surge.sh/vendor.bundle.js:9:2867) at t.remove (http://sparkling-development.surge.sh/vendor.bundle.js:9:15132) at t.u as _dispose

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as catch at Function.e.catchError (http://sparkling-development.surge.sh/vendor.bundle.js:6:19228) at t.e._afterPromiseFinishNavigating (http://sparkling-development.surge.sh/vendor.bundle.js:17:16129) at http://sparkling-development.surge.sh/vendor.bundle.js:17:15234 at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:35:1996) at r.run (http://sparkling-development.surge.sh/vendor.bundle.js:7:10567)

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at t.e.navigateByInstruction (http://sparkling-development.surge.sh/vendor.bundle.js:17:15187) at e.onClick (http://sparkling-development.surge.sh/vendor.bundle.js:18:23684) at e.ChangeDetector_e_0.handleEventInternal (eval at <anonymous> (http://sparkling-development.surge.sh/vendor.bundle.js:5:28498), <anonymous>:1795:41) at e.handleEvent (http://sparkling-development.surge.sh/vendor.bundle.js:5:15438) at e.dispatchEvent (http://sparkling-development.surge.sh/vendor.bundle.js:8:2859)

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at e._createInnerZone (http://sparkling-development.surge.sh/vendor.bundle.js:7:10356) at new e (http://sparkling-development.surge.sh/vendor.bundle.js:7:7864) at i (http://sparkling-development.surge.sh/vendor.bundle.js:7:1237) at t.application (http://sparkling-development.surge.sh/vendor.bundle.js:7:2780) at Object.r as bootstrap at Object.webpackJsonp.0 (http://sparkling-development.surge.sh/bundle.js:1:125) at t (http://sparkling-development.surge.sh/vendor.bundle.js:1:107) at window.webpackJsonp (http://sparkling-development.surge.sh/vendor.bundle.js:1:384)t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 EXCEPTION: TypeError: Cannot read property ‘constructor’ of undefined vendor.bundle.js:13 EXCEPTION: TypeError: Cannot read property ‘constructor’ of undefinedt.logError @ vendor.bundle.js:13 vendor.bundle.js:13 STACKTRACE:t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 TypeError: Cannot read property ‘constructor’ of undefined at Object.n as implementsOnDestroy at Function.e.callPipeOnDestroy (http://sparkling-development.surge.sh/vendor.bundle.js:5:813) at e.ChangeDetector_e_0.dehydrateDirectives (eval at <anonymous> (http://sparkling-development.surge.sh/vendor.bundle.js:5:28498), <anonymous>:86:49) at e.dehydrate (http://sparkling-development.surge.sh/vendor.bundle.js:5:16985) at e.dehydrateView (http://sparkling-development.surge.sh/vendor.bundle.js:9:9535) at t._viewDehydrateRecurse (http://sparkling-development.surge.sh/vendor.bundle.js:9:4435) at t._destroyViewInContainer (http://sparkling-development.surge.sh/vendor.bundle.js:9:4117) at t.destroyViewInContainer (http://sparkling-development.surge.sh/vendor.bundle.js:9:2867) at t.remove (http://sparkling-development.surge.sh/vendor.bundle.js:9:15132) at t.u as _dispose

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at W.catch (http://sparkling-development.surge.sh/vendor.bundle.js:42:5788) at W.e.(anonymous function) as catch at Function.e.catchError (http://sparkling-development.surge.sh/vendor.bundle.js:6:19228) at t.e._afterPromiseFinishNavigating (http://sparkling-development.surge.sh/vendor.bundle.js:17:16129) at http://sparkling-development.surge.sh/vendor.bundle.js:17:15234

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at r.bind (http://sparkling-development.surge.sh/vendor.bundle.js:35:1686) at r (http://sparkling-development.surge.sh/vendor.bundle.js:35:13629) at W.e.(anonymous function) as then at t.e.navigateByInstruction (http://sparkling-development.surge.sh/vendor.bundle.js:17:15187) at e.onClick (http://sparkling-development.surge.sh/vendor.bundle.js:18:23684) at e.ChangeDetector_e_0.handleEventInternal (eval at <anonymous> (http://sparkling-development.surge.sh/vendor.bundle.js:5:28498), <anonymous>:1795:41) at e.handleEvent (http://sparkling-development.surge.sh/vendor.bundle.js:5:15438) at e.dispatchEvent (http://sparkling-development.surge.sh/vendor.bundle.js:8:2859)

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at e._createInnerZone (http://sparkling-development.surge.sh/vendor.bundle.js:7:10356) at new e (http://sparkling-development.surge.sh/vendor.bundle.js:7:7864) at i (http://sparkling-development.surge.sh/vendor.bundle.js:7:1237) at t.application (http://sparkling-development.surge.sh/vendor.bundle.js:7:2780) at Object.r as bootstrap at Object.webpackJsonp.0 (http://sparkling-development.surge.sh/bundle.js:1:125) at t (http://sparkling-development.surge.sh/vendor.bundle.js:1:107) at window.webpackJsonp (http://sparkling-development.surge.sh/vendor.bundle.js:1:384)t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 EXCEPTION: Attempt to detect changes on a dehydrated detector. vendor.bundle.js:13 EXCEPTION: Attempt to detect changes on a dehydrated detector. vendor.bundle.js:13 EXCEPTION: Attempt to detect changes on a dehydrated detector.t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 STACKTRACE:t.logError @ vendor.bundle.js:13 vendor.bundle.js:13 Error: Attempt to detect changes on a dehydrated detector. at t as constructor at new t (http://sparkling-development.surge.sh/vendor.bundle.js:4:17175) at e.throwDehydratedError (http://sparkling-development.surge.sh/vendor.bundle.js:5:20856) at e.detectChangesInRecords (http://sparkling-development.surge.sh/vendor.bundle.js:5:16332) at e.runDetectChanges (http://sparkling-development.surge.sh/vendor.bundle.js:5:15925) at e._detectChangesContentChildren (http://sparkling-development.surge.sh/vendor.bundle.js:5:17779) at e.runDetectChanges (http://sparkling-development.surge.sh/vendor.bundle.js:5:15956) at e._detectChangesInViewChildren (http://sparkling-development.surge.sh/vendor.bundle.js:5:17905) at e.runDetectChanges (http://sparkling-development.surge.sh/vendor.bundle.js:5:16035) at e._detectChangesContentChildren (http://sparkling-development.surge.sh/vendor.bundle.js:5:17779)

-----async gap----- Error at r (http://sparkling-development.surge.sh/vendor.bundle.js:42:7038) at r.fork (http://sparkling-development.surge.sh/vendor.bundle.js:42:7964) at e._createInnerZone (http://sparkling-development.surge.sh/vendor.bundle.js:7:10356) at new e (http://sparkling-development.surge.sh/vendor.bundle.js:7:7864) at i (http://sparkling-development.surge.sh/vendor.bundle.js:7:1237) at t.application (http://sparkling-development.surge.sh/vendor.bundle.js:7:2780) at Object.r as bootstrap at Object.webpackJsonp.0 (http://sparkling-development.surge.sh/bundle.js:1:125) at t (http://sparkling-development.surge.sh/vendor.bundle.js:1:107) at window.webpackJsonp (http://sparkling-development.surge.sh/vendor.bundle.js:1:384) `