【发布时间】:2019-07-26 10:12:52
【问题描述】:
我正在使用角度步进器,我需要在其中一个步骤中显示一个组件。我需要单击一个按钮来加载该组件。我可以看到子组件被插入,但它没有正确显示。当我检查并转到“元素”选项卡中的该元素时,我可以看到插入的组件,当我悬停时,浏览器会在最右边突出显示。这是路由模块:
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
]
})
parent-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>
parent-stepper.component.ts
load(){
this._route.navigate(['subitem'], {relativeTo: this._ac});
}
如果有人可以建议我在这里做错了什么?
注意:我发现问题主要出在 Material stepper 上。如果我添加一个条件,那么它会正确显示。但是这样做的问题是它多次加载相同的组件。如果有人可以提出更优雅的解决方案。
【问题讨论】:
-
我想你忘记了父级中的
-
我的主要组件是应用程序组件,我还有另一个路由器插座。父组件是另一个我需要加载子组件的组件。
-
即使那里也需要放路由器插座
-
我在按钮标签下方的 parent-stepper.html 中有
。而且我能够正确路由到它,我也可以看到插入的组件。我在子组件 ngOninit() 中添加了一个 console.log,可以看到打印的日志,但这是导致问题的可见性。 -
可能是css显示:无问题
标签: angular angular-ui-router angular2-routing angular-material-stepper