Used to have, with deprecated router, a few components that routed to the same component:
Some Component
import {Component, Injector} from 'angular2/core';
import {IDataServiceSome} from './IDataServiceSome';
import {RouteData} from 'angular2/router';
@Component({
selector: 'Some',
templateUrl: './Some.html'
})
export class Some {
Model;
DataService: IDataServiceVendor;
constructor(routeData: RouteData, injector: Injector) {
var dataServiceToken = routeData.get('DataServiceToken');
this.DataService = injector.get(dataServiceToken);
this.Model = DataService.getSomeModel();
}
}
IDataServiceSome
export interface IDataServiceSome {
getSomeModel(): Object;
}
e.g. Comp1 but there are Comp2, Comp3, etc...
import {Component} from 'angular2/core';
import {RouteConfigs, Router, ROUTER_DIRECTIVES} from 'angular2/router';
import {DataServiceSome1} from './IDataServiceSome1';
@RouteConfigs([
{ path: '/Some', name: 'Some', component: Some, data: { DataServiceToken: DataServiceSome1 } }])
@Component({
directives: [ROUTER_DIRECTIVES],
providers: [DataServiceSome1],
selector: 'Comp1',
template:
`<div>
<router-outlet></router-outlet>
<h1>Comp1 routed to Some</h1>
</div>`
})
export class Comp1{
}
As you might have guessed, there are many data services that implement IDataServiceSome
and many components that route to Some
. The choice of which data service is used, comes from any component that routes to Some
component using a data token known to injector
. With rc1 release and new router, the RouteData
is deprecated or removed, but how is this scenario implemented moving forward?