我有一个旧的角度模块,可用作系统中的主要模块。 现在,我想在一个使用不同主模块的新角度骨架\框架中实现该模块( MyOldModule )。 AdminLayoutComponent 是主要组件。 MyOldModule 是我要实现的旧模块 OldComponent 是有问题的组件,不是“熟悉”的。
未捕获的错误:模板解析错误: 无法绑定到“ ngForOf”,因为它不是“旧组件”的已知属性。 (old-component是 OldComponent 的选择器名称)
这是app.module:
@NgModule({
imports: [
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
ComponentsModule,
**RouterModule**,
AppRoutingModule,
MyOldModule //This is the "old" module I want to include
})
],
declarations: [
AppComponent,
AdminLayoutComponent
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
这是 routerModule :
const routes: Routes =[
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full',
},
{
path: '',
component: AdminLayoutComponent,
children: [
{
path: 'mycomponentPath', //This is the "old" component located in my MyOld Module
loadChildren: './OldModule/MyOld.module#MyOldModule'
},
{
path: '',
loadChildren: './layouts/admin-layout/admin-layout.module#AdminLayoutModule'
}
]
}
];
@NgModule({
imports: [
CommonModule,
BrowserModule,
RouterModule.forRoot(routes,{
useHash: true
})
],
exports: [
],
})
export class AppRoutingModule { }
这是 AdminLayoutModule :
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(AdminLayoutRoutes),
FormsModule,
ReactiveFormsModule,
MyOldModule
],
declarations: [
ComponentA,
...
]
})
export class AdminLayoutModule {}
这是MyOldModule:
@NgModule({
declarations: [
OldComponent
],
imports: [
FormsModule,
HttpClientModule,
AppRoutingModule,
MyOldRoutingModule,
],
exports:[],
providers: [MyService],
bootstrap: [AppComponent]
})
export class MyOldModule { }
这是 MyOldRoutingModule :
const routes: Routes = [
{ path: 'oldPath', component: OldComponent },
]
@NgModule({
imports: [RouterModule.forChild(routes) ],
exports: [RouterModule]
})
export class MyOldRoutingModule { }
这是OldComponent:
<div *ngFor="let page of pages" class="scroll"> </div>
答案 0 :(得分:0)
您的AdminLayoutModule
似乎没有导入BrowserModule
。因此添加它:
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(AdminLayoutRoutes),
FormsModule,
ReactiveFormsModule,
BrowserModule,
MyOldModule
],
declarations: [
ComponentA,
...
]
})
export class AdminLayoutModule {}