【发布时间】:2020-05-22 16:02:00
【问题描述】:
我正在努力将 Angular JS 应用程序转换为 Angular,但我被困在一个地方。我在 html 中有一个旧的 ng-repeat 循环,它在 JS 中有效,但不再有效。它旨在在页面上导航到带有 id 标记的部分。
旧
<ul >
<li ng-repeat="tag in vm.tags">
<a href="#{{tag.id}}" ng-click="vm.highlightSection(tag.id)">{{tag.display}}</a>
</li>
</ul>
新
<ul>
<li *ngFor="let tag of (noteItem$ | async)?.tags">
<a (click)="vm.highlightSection(tag.id)">{{tag.display}}</a>
</li>
</ul>
插值抓取tag.display就好了。但是 vm.highlightSection(tag.id) 没有在页面内导航到请求的标签 ID。我该怎么做才能让导航链接引用我的标签 ID 并在那里导航?
谢谢
【问题讨论】:
-
vm在哪里声明?为什么你不直接调用像“highlightSection”这样的方法
标签: angular navigation angularjs-ng-repeat href ngfor