You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't you think that having to use @Inject for ROUTE_DATA is a bit surprising compared to RouteParams which gives us a service? I think this is a very rare case (the only one?) where we can't rely on Type annotation in an app for something provided by the framework. And we obtain an object, whereas RouteParams provides a get method.
constructor(routeParams: RouteParams, @Inject(ROUTE_DATA) routeData) {
let id = routeParams.get('id');
let name = ROUTE_DATA.name;
}
A less surprising (and more coherent and friendly in my opinion) would be:
constructor(routeParams: RouteParams, routeData: RouteData) {
let id = routeParams.get('id');
let name = routeData.get('name');
}
The injector allows for any token include types. I agree with @cexbrayat that we should allow the type token RouteData on the merit that it's a valid token. I guess naming conventions should also have ref in the name RouteParamsRef and RouteDataRef. The real problem here is that ROUTE_DATA can only guarantee a shallow copy (since only two types are allowed array|object) as it's unaware of the types you provide. Unless data is a factory
or perhaps the bindings in router-outlet is missing bind(ComponentInstruction).toValue(nextInstruction) and RouteConfig needs to include bindings prop. Adding these two seems to be the best option since anyone can create their own conventions
Activity
cexbrayat commentedon Sep 28, 2015
cc @btford @TommyM @PascalPrecht
PatrickJS commentedon Sep 28, 2015
The injector allows for any token include types. I agree with @cexbrayat that we should allow the type token
RouteDataon the merit that it's a valid token. I guess naming conventions should also have ref in the nameRouteParamsRefandRouteDataRef. The real problem here is thatROUTE_DATAcan only guarantee a shallow copy (since only two types are allowed array|object) as it's unaware of the types you provide. Unlessdatais a factoryif not
RouteDatathan perhapsRouteConfigRefor perhaps the bindings in router-outlet is missing
bind(ComponentInstruction).toValue(nextInstruction)andRouteConfigneeds to includebindingsprop. Adding these two seems to be the best option since anyone can create their own conventionsmhevery commentedon Sep 29, 2015
👍 for having
RouteDatatype so that it can be cleanly injected.btford commentedon Sep 29, 2015
I think I'm convinced a type would be better.
PR welcome :)
cexbrayat commentedon Sep 30, 2015
@mhevery @btford Thx for your answers.
Do we agree on a
RouteDatatype that we can inject, and which would offer a getter (asRouteParamsdoes)?If so, I guess a
Routedata should be a simple object, like:Would that be OK?
cexbrayat commentedon Sep 30, 2015
(I opened a related PR #4428 to start the discussion, feedback welcome)
0x-r4bbit commentedon Sep 30, 2015
@cexbrayat thanks for starting this, I already took a look and it LVGTM!
6 remaining items
refactor(router): RouteData as a type
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.