简体   繁体   English

Angular 8 routerLinkActive不适用于ng-template

[英]Angular 8 routerLinkActive doesn't work with ng-template

I'm having trouble with the routerLinkActive attribute in angular 8. When rendering a link with the attribute inside an ng-template the routerLinkActive class is not applied to the parent element when the link is active. 我在angular 8中遇到了routerLinkActive属性的问题。当在ng-template内使用该属性呈现链接时,当该链接处于活动状态时,routerLinkActive类不会应用于父元素。 Ie.. 即..

<div routerLinkActive="active2">
  <ng-container [ngTemplateOutlet]="test" [ngTemplateOutletContext]="{link: '/home', name: 'Home'}"></ng-container> |
</div>

<ng-template #test let-link="link" let-name="name">
  <a routerLinkActive="active" [routerLink]="[link]">{{name}}</a>
</ng-template>

Seems to have stopped working since I updated to Angular 8. 自从我更新到Angular 8以来似乎已经停止工作。

Stackblitz Demo Stackblitz演示

check the below solution 检查以下解决方案

https://stackblitz.com/edit/angular-routelinkactive-broken-template-g3cxxt https://stackblitz.com/edit/angular-routelinkactive-broken-template-g3cxxt

I have merged 2 css classes into one 我已经将2个CSS类合并为一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM