2

I'm using the following template statement to determine the class of a tab element:

<li [class.active]="router.url == '/member-view/member-profile/' + routeParamVar">

The class should be active regardless of what the route parameter is. But ideally I can drop the specific route param into the Router.url statement. This is the first part of this question and it seems fairly straight forward, but I'm not sure how to do it.

A complication, I believe, is that this element is in the parent template of the view with the actual route param. It doesn't seem like I'm able to assign the ActivatedRoute param to a variable in the component like this:

this.uid = this.activeRoute.snapshot.params['uid']

I've messed around with using a service or @ViewChild to get the uid from the child to the parent, but haven't quite figured it out yet. So in summary my question is twofold:

First, how can I assign the route param of a child component to a variable in the parent component?

Second, how might I get that variable into the Router.url in the template statement?

1 Answer 1

1

So the way to reference the variable in the Router.url is as I guessed in the question:

[class.active]="router.url === '/member-view/member-profile/' + uid"

I was also able to get the route param of the child with:

this.activeRoute.firstChild.params
.subscribe(params => {
    this.uid = params['uid'];
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.