Angular 8: Cannot read property 'runOutsideAngular' of undefined

纵然是瞬间 提交于 2019-12-25 01:14:04

问题


When i run my app locally there is no problem whatsoever, but when the app is hosted (on firebase hosting) whenever I try to navigate to a page I get the following error: Cannot read property 'runOutsideAngular' of undefined. Because the code is minified to main.js I can't seem to find why the error is thrown. The error is thrown when the router should navigate to a different page.

  {
    path: 'manage/:bookingid',
    component: ManageBookingComponent
  },

Both pages use an Angular material Sidenav (removing them from the page doesn't resolve the error). I found this StackOverflow question, but none of the answers seem to work.

I've tried using template routing:

[routerLink]="['/', 'manage', booking.id]"

and component routing:

this.router.navigateByUrl(`/manage/${booking.id}`)

or

this.router.navigate(['/', 'manage', booking.id])

locally all these options work, hosted this is a different story..

EDIT: further research may indicate it to be a issue between Angular Material and Router, see this SO question


回答1:


It is an issue with the AoT-compiler. It happens in your production builds because of AoT. A fix is to go to tsconfig.json and change your target to es5 under compilerOptions.

I would try bumping your @angular-versions first, since the issue is closed.



来源:https://stackoverflow.com/questions/59253896/angular-8-cannot-read-property-runoutsideangular-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!