Angular 2 routerlink with multiple routes?

后端 未结 2 888

I want to remove a class only one ONE route, (Or add a class on all BUT one route.) How is that possible? I have tried [routerLink] with multiple parameters to no avail:

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-20 06:01

    Here's my final solution which just used the [class] attribute. BTW, What happened to the [ng-class] attribute in Angular2?:

    HTML:

    TypeScript:

    import {Location} from '@angular/common';
    ...
    constructor(private authService: AuthService,private location: Location) { }
    ...
    bodyContentClass()
    {
        // router  is an instance of Router, injected in the constructor
       var viewLocation = location.pathname; 
       return viewLocation == '/counter' || viewLocation == '/fetch-data' ? 'col-sm-9' : '';
    }
    

提交回复
热议问题