I have a route in my router module /dashboard. In this route I have multiple components including a parent component and several child components. I pass data (tablesPanorama (Array of objects)) from the parent component called TischplanComponent (tischplan.component.ts) to a child component called DepartmentsComponent (departments.component.ts) with the @Input decorator.
app.module.ts
const appRoutes: Routes = [
{path: '', component: LoginComponent},
{path: 'login', component: LoginComponent},
{path: 'dashboard', component: TischplanComponent, canActivate: [AuthGuard]},
{path: 'register', component: RegisterComponent},
{path: 'profile', component: ProfileComponent, canActivate: [AuthGuard]}
];
imports: [RouterModule.forRoot(appRoutes)]
app-component-html
This is where the router-outlet lies
<router-outlet></router-outlet>
tischplan.component.html
<app-departments [tablesPanorama]="tablesPanorama"</app-departments>
departments.component.ts
@Input('tablesPanorama') tablesPanorama: Table[];
Unfortunately the data is not passed to the child component. What causes this problem? If I console.log this.tablesPanorama in the constructor I get undefined:
constructor(private tischplanService: TischplanService) {
console.log("this.tablesPanorama:");
console.log(this.tablesPanorama);
}
The connection between the @Input
and the <router-outlet>
:
As far as I understand my code, the @Input
is in the child component called DepartmentComponent which passes the variable tablesPanorama from the parent component TischplanComponent, which is the component of the /dashboard route in the <router-outlet>
, which lies in the app.component.ts.
@Input()
is not supported on components added by the router. It's not clear how@Input()
and<router-outlet>
are related in your question. – Günter Zöchbauer