I am using a stepper in angular and I need to display a component in one of the steps. I need to click on a button to load that component. I can see the child component getting inserted but it's not displaying correctly. When I inspect and go to that element in "Elements" tab then I can see the component inserted and when I hover then browser highlights at the right most corner. Here is routing module:
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});
}
If someone can suggest what I'm doing wrong here?
Note: I figured out that the problem is primarily with Material stepper. If I add a condition in then it displays it correctly. But the problem with this is that it loads the same component multiple times. If someone can suggest a more elegant solution.