When I load MatProgressSpinnerModule into app.module.ts I get empty NG0203 error with "stacktrace":
tQ
re
fac
hydrate
get
_resolveInjectorDefTypes
_resolveInjectorDefTypes
PM
create
wA
invoke
onInvoke
invoke
run
run
bootstrapModuleFactory
wA
invoke
run
F
invokeTask
runTask
L
promise callback*d
scheduleTask
scheduleTask
scheduleMicroTask
F
then
bootstrapModule
636
n
<anonymous>
a
<anonymous>
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from "@angular/common/http";
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { AppComponent } from './app.component';
import { SongbookService } from './services/songbookService';
import router from './router';
import { InterceptorService } from './services/InterceptorService';
import { SpinnerService } from './services/spinnerService';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
HttpClientModule,
BrowserAnimationsModule,
MatProgressSpinnerModule,
router
],
providers: [
SongbookService,
{ provide: HTTP_INTERCEPTORS, useClass: InterceptorService, multi: true },
SpinnerService
],
bootstrap: [AppComponent]
})
export class AppModule { }
I have no idea how to fix it, when I rem MatProgressSpinnerModule in NgModule imports - error does not appear. Same issue with ngx-spinner.
If that matter its SPA in .NET application
2 Answers
I've also experienced an error "NG0203 inject() must be called from an injection context" from one day to another without really changing something.
I stumbled over following solution which worked in my case:
The suggestion is to adjust the compilerOptions within tsconfig.json adding the path for the angular modules as follows:
{
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"paths": {
//[...]
"@angular/*": [ "./node_modules/@angular/*"]
},
//[...]
}
}
Hope it helps...
This also happened when I tried to use effect out of component in Agular 16.