| OLD | NEW |
| 1 part of angular.routing; | 1 part of angular.routing; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * A directive that allows to bind child components/directives to a specific | 4 * A directive that allows to bind child components/directives to a specific |
| 5 * route. | 5 * route. |
| 6 * | 6 * |
| 7 * <div ng-bind-route="foo.bar"> | 7 * <div ng-bind-route="foo.bar"> |
| 8 * <my-component></my-component> | 8 * <my-component></my-component> |
| 9 * </div> | 9 * </div> |
| 10 * | 10 * |
| 11 * ng-bind-route directives can be nested. | 11 * ng-bind-route directives can be nested. |
| 12 * | 12 * |
| 13 * <div ng-bind-route="foo"> | 13 * <div ng-bind-route="foo"> |
| 14 * <div ng-bind-route=".bar"> | 14 * <div ng-bind-route=".bar"> |
| 15 * <my-component></my-component> | 15 * <my-component></my-component> |
| 16 * </div> | 16 * </div> |
| 17 * </div> | 17 * </div> |
| 18 * | 18 * |
| 19 * The '.' prefix indicates that bar route is relative to the route in the | 19 * The '.' prefix indicates that bar route is relative to the route in the |
| 20 * parent ng-bind-route or ng-view directive. | 20 * parent ng-bind-route or ng-view directive. |
| 21 * | 21 * |
| 22 * ng-bind-route overrides [RouteProvider] instance published by ng-view, | 22 * ng-bind-route overrides [RouteProvider] instance published by ng-view, |
| 23 * however it does not effect view resolution by nested ng-view(s). | 23 * however it does not effect view resolution by nested ng-view(s). |
| 24 */ | 24 */ |
| 25 @NgDirective( | 25 @Decorator( |
| 26 visibility: NgDirective.CHILDREN_VISIBILITY, | |
| 27 publishTypes: const [RouteProvider], | |
| 28 selector: '[ng-bind-route]', | 26 selector: '[ng-bind-route]', |
| 29 map: const { | 27 module: NgBindRoute.module, |
| 30 'ng-bind-route': '@routeName' | 28 map: const {'ng-bind-route': '@routeName'}) |
| 31 }) | 29 class NgBindRoute implements RouteProvider { |
| 32 class NgBindRouteDirective implements RouteProvider { | |
| 33 Router _router; | 30 Router _router; |
| 34 String routeName; | 31 String routeName; |
| 35 Injector _injector; | 32 Injector _injector; |
| 36 | 33 |
| 34 static final Module _module = new Module() |
| 35 ..factory(RouteProvider, |
| 36 (i) => i.get(NgBindRoute), |
| 37 visibility: Directive.CHILDREN_VISIBILITY); |
| 38 static module() => _module; |
| 39 |
| 37 // We inject NgRoutingHelper to force initialization of routing. | 40 // We inject NgRoutingHelper to force initialization of routing. |
| 38 NgBindRouteDirective(this._router, this._injector, NgRoutingHelper _); | 41 NgBindRoute(this._router, this._injector, NgRoutingHelper _); |
| 39 | 42 |
| 40 /// Returns the parent [RouteProvider]. | 43 /// Returns the parent [RouteProvider]. |
| 41 RouteProvider get _parent => _injector.parent.get(RouteProvider); | 44 RouteProvider get _parent => _injector.parent.get(RouteProvider); |
| 42 | 45 |
| 43 Route get route => routeName.startsWith('.') ? | 46 Route get route => routeName.startsWith('.') ? |
| 44 _parent.route.getRoute(routeName.substring(1)) : | 47 _parent.route.getRoute(routeName.substring(1)) : |
| 45 _router.root.getRoute(routeName); | 48 _router.root.getRoute(routeName); |
| 46 | 49 |
| 47 Map<String, String> get parameters { | 50 Map<String, String> get parameters { |
| 48 var res = <String, String>{}; | 51 var res = <String, String>{}; |
| 49 var p = route; | 52 var p = route; |
| 50 while (p != null) { | 53 while (p != null) { |
| 51 res.addAll(p.parameters); | 54 res.addAll(p.parameters); |
| 52 p = p.parent; | 55 p = p.parent; |
| 53 } | 56 } |
| 54 return res; | 57 return res; |
| 55 } | 58 } |
| 56 } | 59 } |
| OLD | NEW |