We use angular-ui-router.js v 0.2.18 + angular-ui-router.d.ts v 1.4.6 (typescript v 1.8.36.0).
So we use IStateProvider
to configure navigation from one state to another.
Often we need to pass some state parameters from father state to child state.
Config:
.state(States.MeasureDetail, {
parent: States.OperatorView,
templateUrl: '/App/Business/Kanban/BuildAndCureKanban/Views/MeasureDetail.html',
controller: Controllers.MeasureDetailController,
controllerAs: 'measureDetailCtrl',
params:
{
machine: null,
material: null
}
})
In father controller:
this.$state.go(States.MeasureDetail, {
machine: this.currentMachine,
material: this.currentMaterial
});
In child controller:
constructor(
private buildAndCureService: Services.IBuildAndCureService,
private $state: ng.ui.IStateService,
private eventManager: _Common.Services.IEventManager){
this.machine = $state.params["machine"];
this.material = $state.params["material"];
}
The problem
Neither params property nor IStateParameterService interface are strongly typed: you access by key and obtain an any type.
params?: any;
interface IStateParamsService {
[key: string]: any;
}
This is a weakness that, in big projects with many developers, has already brought to runtime issues.
The question
I know that is possible to extend IStateParameterService like the example in this post to add a typed field, but the solution is once for all states, whereas I need a solution to add typed fields state by state.
How can I extended IStateParameterService to have something like:
interface IStateParamsService {
CustomParam<T>?: T;
}
?
Thanks.