I have a component which has a @Routeconfig
(the parent).
import {Component} from "angular2/core";
import {RouteConfig,ROUTER_DIRECTIVES, RouterOutlet} from 'angular2/router';
import {Theme} from "../theme/theme";
import {Router,RouteParams} from "angular2/router";
import {OrganisationService} from "./organisation.service";
import {Organisation} from "./organisation";
import {OrganisationComponent} from "./organisation.component";
import {EmptyComponent} from "../../empty.component";
import {ThemeListComponent} from "../theme/theme-list.component";
@Component({
template: `
<div class="container">
<ul>
<li *ngFor="#organisation of organisations">
<a [routerLink]="['./ThemeList',{ organisationId: organisation.organisationId }]" >{{organisation.organisationName}}</a>
</li>
</ul>
</div>
<router-outlet></router-outlet>
`,
directives:[RouterOutlet],
providers:[OrganisationService]
})
@RouteConfig([
{path: '/', name:'Empty', component:EmptyComponent,useAsDefault: true},
{path: '/:organisationId/Themes/...', name:'ThemeList', component:ThemeListComponent}
])
export class OrganisationListComponent {
public organisations:Organisation[];
constructor(private organisationService:OrganisationService) {
this.organisationService.getOrganisations().subscribe((organisations:Organisation[])=> {
this.organisations = organisations;
});
}
}
I want to sent the id from organisation to my ThemeListComponent
(child). This works but when i try to get the routeParams withing my child component it gives errors.
EXCEPTION: Error during instantiation of Router! (RouterLink -> Router).
ORIGINAL EXCEPTION: Route config should contain exactly one "component", "loader", or "redirectTo" property.
This is ThemeListComponent and how i try to receive the routerParams:
import {Component} from "angular2/core";
import {RouteConfig,ROUTER_DIRECTIVES, RouterOutlet} from 'angular2/router';
import {Theme} from "../theme/theme";
import {Router,RouteParams} from "angular2/router";
import {ThemeComponent} from "../theme/theme.component";
import {ThemeService} from "./theme.service";
import {EmptyComponent} from "../../empty.component";
@Component({
template: `
<div class="container">
<ul>
<li *ngFor="#theme of themes">
<a [routerLink]="['./Theme',{ themeId: theme.themeId }]">{{theme.name}}</a>
</li>
</ul>
</div>
<router-outlet></router-outlet>
`,
directives:[RouterOutlet,RouteParams],
providers:[ThemeService]
})
@RouteConfig([
{path: '/', name:'Empty', component:EmptyComponent,useAsDefault: true},
{path: '/:themeId', name:'Theme', component:ThemeComponent}
])
export class ThemeListComponent {
public themes:Theme[];
constructor(private themeService:ThemeService,private routeParams:RouteParams) {
let id = +this.routeParams.get('id');
this.themeService.getThemes(id).subscribe((themes:Theme[])=>{
this.themes = themes;
});
}
}
I get the errors whenever i just implement the routerParams in my constructor in the child.