【发布时间】:2020-06-03 10:19:57
【问题描述】:
我有一个简单的函数来根据 url 为导航设置活动状态:
angular.forEach(this.$filter('filter')(this.fullNav, {
'link': this.$location.$$path
}, true), (item) => {
item.active = true;
});
现在我想添加要突出显示的旧 URL。我有 links 而不是链接(如果有多个链接,但我可以将所有链接参数设为数组。
为了让它与链接和链接参数一起工作,我对此进行了更改:
angular.forEach(this.fullNav, (item) => {
if(item.links) {
if(item.links.includes(this.$location.$$path)) {
item.active = true;
}
} else {
if(item.link === this.$location.$$path) {
item.active = true;
}
}
});
如何以 $filter 形式编写第二个函数?或者至少没有 if else 语句(通过删除 link 属性并仅具有 links 属性)。
【问题讨论】:
标签: angularjs angularjs-filter