1

In a template I have the following routerLink: [routerLink]="['../myObjects', {'id': object.id}, 'mySubObjectsList']"

The routing is ok, but I cannot get the parameter value id in my mySubObjectsList component. _routeParams.params is empty.

I guess this is because the parameter is set to my parent routing component myObjects.

Is there a way to get it in my subcomponent?

Thanks for your help.

1 Answer 1

1

I don't think there is an easy way. You can add the params to a service in the parent and make that service available to the child:

@Service()
class ParentRouteParams {
  Map<String,String> params;
  // using a StreamController is probably a good idea
}

@Component(
  selector: 'parent',
  providers: const [ParentRouteParams],
  ...
)
class Parent {
  Parent(this._parentRouteParams);

  final ParentRouteParams _parentRouteParams;

  @override
  void onActivate(_, RouterState current) {
    _parentRouteParams.params = current.parameters;
  }
}
@Component(
  selector: 'child'
  ...
)
class Child {
  Parent(this._parentRouteParams);

  final ParentRouteParams _parentRouteParams;

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.