Provide application level module in bootstrapApplication
bootstrapApplication(AppComp, {
providers: [
importProvidersFrom(HttpClinetModule)
]
})
//BAD
@Component({
standlone: true,
imports: [CommonModule, RouterModule, /*bad*/ HttpClinetModule]
})
class OldCmp {}
@NgModule({
declaractions: [OldCmp],
imports: [CommonModule, HttpClinetModule, RouterModule]
})
When you want to share some provider for app the children component, for example, NgrxStore:
export default const ROUTES = [
// make an empty parent route
{
path: '',
providers: [
importProvidersFrom(NgrxStore.forFeature(...))
],
children: [
{path: '', component: HomeCmp}, {path: 'admin', component: AdminCmp, providers: [{provide: AuthService, useClass: AdminAuthService}]}
]
}
]
标签:providers,provide,component,level,share,routes,path From: https://www.cnblogs.com/Answer1215/p/16749535.html