question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

md-tab-nav-bar does not properly display active when child/relative routes are involved (removing the md- directives fix this)

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Any active routerLinks with the md-tab-link directive should show the material design active styling

What is the current behavior?

Paths with children and or relative paths seem to break the md-tab-nav-bar active styling (the individual tabs do not show the active styling when the corresponding route is active).

What are the steps to reproduce?

I created a repo reproducing the problem at: https://github.com/danwulff/md-tab-nav-bar-error-with-children

Steps to reproduce:

  • In a terminal $ git clone https://github.com/danwulff/md-tab-nav-bar-error-with-children && cd md-tab-nav-bar-error-with-children && npm install && ng serve
  • browser to http://localhost:4200/
  • click ‘sub route’
  • click through the tabs to see that the first 3 don’t work

The markup of the tabs is found within sub.component.html

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

@angular/cdk, @angular/material: 2.0.0-beta.8 Tested in Google Chrome 59

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
willshowellcommented, Jul 22, 2017

Just took a look and there are two issues with your markup:

  1. md-tab-nav requires that only one tab is considered active at a time. This means that duplicating tabs for sub/ (or “one”) will behave unexpectedly. So the first step is to be sure to only use a single tab for any unique route

  2. In your master branch, you are redefining #rla for each tab. AFAIK the scope of this reference is template-wide, so really you’re just overwriting it 3 times. Opt for using a unique template reference name for each tab or use *ngFor like below,

<nav md-tab-nav-bar>
  <a md-tab-link *ngFor="let tab of tabs"
    [routerLink]="[tab.path]"
    routerLinkActive
    #rla="routerLinkActive"
    [routerLinkActiveOptions]="{exact: true}"
    [active]="rla.isActive">
    {{ tab.label }}
  </a>
</nav>
  tabs = [
    { path: './', label: 'one' },
    { path: 'two/123', label: 'two with param' },
    { path: 'two', label: 'two' }
  ]

I hope this helps!

1reaction
willshowellcommented, Jul 21, 2017

Without diving into your repo, did you look at using an exact route match?

https://angular.io/api/router/RouterLinkActive#routerLinkActiveOptions

<div routerLinkActive="active-link" [routerLinkActiveOptions]="{exact: true}">
  <a routerLink="/user/jim">Jim</a>
  <a routerLink="/user/bob">Bob</a>
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 6 Cheat Sheet (Part II) - Medium
A directive is a marker that is attached to a DOM element that lets the Angular HTML compiler ($compile) hook specific behaviors to...
Read more >
Using Other route_design Options - 2021.2 English - Xilinx
The -unroute option removes routing for the entire design or for nets and pins, when combined with the nets or pin options. The...
Read more >
Dispatcher Activities - Oracle Help Center
You can drill down to display the route information for any resource, bucket, or group selected in the upper panel. For example, if...
Read more >
The new Angular Router – a simple example - Chariot Solutions
The directives for Angular Material Design help you style your application without a lot of css or container divs. We're going to use...
Read more >
Route Directives - Embedthis
The Action directive may be used to ensure a specific program is used to run CGI scripts. The CGI handler may match URLs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found