问题
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