【发布时间】:2018-10-15 03:32:40
【问题描述】:
我有一个列表组,定义为 recipe-items 列表。我正在使用子路由,以便在用户单击列表元素时显示项目的描述。到目前为止,点击事件和路由都在工作,但 我想将点击的项目标记为活动。
recipe-list.component.html
<app-recipe-item
*ngFor="let recipeEl of recipes; let i = index"
[recipe]="recipeEl"
[routerLink]="i"
style="cursor: pointer;"
>
</app-recipe-item>
为了做到这一点,我尝试在嵌套的 RecipeItemComponent 中使用 routerLinkActive 指令,但看起来该指令超出了嵌套组件的范围。
recipe-item.component.html
<div class="list-group">
<a
class="list-group-item list-group-item-action d-flex justify-content-between align-items-start"
routerLinkActive="active"
>
TO BE MARKED AS ACTIVE WHEN CLICKED
</a>
</div>
我错过了什么?即使使用 localRef 也无法在嵌套组件中检索其值。
【问题讨论】:
标签: angular angular2-routing angular6