我正在使用角度步进器,我需要在其中一个步骤中显示一个组件。我需要单击一个按钮来加载该组件。我可以看到子组件被插入,但它没有正确显示。当我检查并转到“元素”选项卡中的该元素时,我可以看到插入的组件,当我悬停时,浏览器会在最右上角突出显示。这是路由模块:
const routes: Routes = [
{
path: '',
redirectTo: 'items',
pathMatch: 'full'
},
{
path: 'items',
component: ItemsComponent,
pathMatch: 'full'
},
{
path: 'item/:id',
component: ItemStepperComponent,
children: [
{path: 'subitem', component: SubItemComponent, pathMatch: 'full'}
]
},
];
@NgModule({
declarations: [],
imports: [
RouterModule.forRoot(routes)
],
exports: [
RouterModule
]
})
父stepper.html
<mat-horizontal-stepper #stepper [linear]="true">
<mat-step *ngFor = "let step of steps; let i=index" [editable]="true">
<button type="button" mat-raised-button (click) = "load()">Add Sub Item</button>
<router-outlet></router-outlet>
</mat-step>
</mat-horizontal-stepper>
父stepper.component.ts
load(){
this._route.navigate(['subitem'], {relativeTo: this._ac});
}
如果有人可以建议我在这里做错了什么?
注意:我发现问题主要出在 Material stepper 上。如果我添加一个条件,那么它会正确显示。但是这样做的问题是它多次加载相同的组件。如果有人可以提出更优雅的解决方案。