[Angular] Standalone component - routes top level provide share for all child routes
Angular for all Component Top level child share
2023-09-14 09:00:45 时间
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}]}
]
}
]
相关文章
- angular 路由懒加载_angular路由
- Angular 应用开发里使用 ForRoot 解决 Lazy Loaded Module 里单例行为丢失的问题
- Angular RouterModule.forRoot(ROUTES) 和 forChild(ROUTES)的区别
- Angular 应用 tsconfig.json 文件里的 typeRoots 属性讲解
- 使用 Angular HTTP_INTERCEPTOR 拦截器来记录超时请求的一些思考
- Angular 依赖注入错误消息:ERROR Error NullInjectorError No provider for XX
- MySQL使用For循环实现数据操作(mysql写for循环)
- 使用For循环掌控Oracle数据库(for循环oracle)
- 进程探索Linux中For循环进程管理(linux中for)
- MySQL存储过程中使用FOR循环的实现(mysql存储过程for循环)
- 循环使用Oracle数组实现For循环(oracle数组for)
- MySQL中使用FOR循环的实践(mysql的for循环)
- Linux下如何优雅地使用For循环(linux下for循环)
- Oracle:学习如何使用For遍历(oracle for遍历)
- 使用For语句操作Oracle数据库(for语句 oracle)