I need to use a service to configure a module inside app.module, just like that:
imports: [
CommonModule,
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
AppRoutingModule,
targetModule.forRoot({
'var1': environmentService.var1,
}),
anotherModule,
],
how to create an instance of EnvironmentService in this case? EnvironmentService is "providedIn: root" service
@Injectable({
providedIn: 'root',
})
use inject
from @angular/core
module
import {NgModule, inject} from '@angular/core';
const injectedVal = inject(environmentService).var1;
imports: [
CommonModule,
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
AppRoutingModule,
targetModule.forRoot({
'var1': injectedVal,
}),
anotherModule,
],
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.