| 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 * |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 @NgDirective( |
| 26 visibility: NgDirective.CHILDREN_VISIBILITY, | 26 visibility: NgDirective.CHILDREN_VISIBILITY, |
| 27 publishTypes: const [RouteProvider], | 27 publishTypes: const [RouteProvider], |
| 28 selector: '[ng-bind-route]', | 28 selector: '[ng-bind-route]', |
| 29 map: const { | 29 map: const { |
| 30 'ng-bind-route': '@routeName' | 30 'ng-bind-route': '@routeName' |
| 31 }) | 31 } |
| 32 ) |
| 32 class NgBindRouteDirective implements RouteProvider { | 33 class NgBindRouteDirective implements RouteProvider { |
| 33 Router _router; | 34 Router _router; |
| 34 String routeName; | 35 String routeName; |
| 35 Injector _injector; | 36 Injector _injector; |
| 36 | 37 |
| 37 // We inject NgRoutingHelper to force initialization of routing. | 38 // We inject NgRoutingHelper to force initialization of routing. |
| 38 NgBindRouteDirective(this._router, this._injector, NgRoutingHelper _); | 39 NgBindRouteDirective(this._router, this._injector, NgRoutingHelper _); |
| 39 | 40 |
| 40 /// Returns the parent [RouteProvider]. | 41 /// Returns the parent [RouteProvider]. |
| 41 RouteProvider get _parent => _injector.parent.get(RouteProvider); | 42 RouteProvider get _parent => _injector.parent.get(RouteProvider); |
| 42 | 43 |
| 43 Route get route => routeName.startsWith('.') ? | 44 Route get route { |
| 44 _parent.route.getRoute(routeName.substring(1)) : | 45 if (routeName.startsWith('.')) { |
| 45 _router.root.getRoute(routeName); | 46 return _parent.route.getRoute(routeName.substring(1)); |
| 47 } else { |
| 48 return _router.root.getRoute(routeName); |
| 49 } |
| 50 } |
| 46 | 51 |
| 47 Map<String, String> get parameters { | 52 Map<String, String> get parameters { |
| 48 var res = <String, String>{}; | 53 var res = <String, String>{}; |
| 49 var p = route; | 54 var p = route; |
| 50 while (p != null) { | 55 while (p != null) { |
| 51 res.addAll(p.parameters); | 56 res.addAll(p.parameters); |
| 52 p = p.parent; | 57 p = p.parent; |
| 53 } | 58 } |
| 54 return res; | 59 return res; |
| 55 } | 60 } |
| 56 } | 61 } |
| OLD | NEW |