AngularJS 过滤器检查数组参数是否包含值

AngularJS filter where checking if array parameter contains value

我有一个简单的功能可以根据 url:

设置导航的活动状态
angular.forEach(this.$filter('filter')(this.fullNav, {
    'link': this.$location.$$path
}, true), (item) => {
    item.active = true;
});

现在我想添加旧版 URL 以同时突出显示。而不是 link 我有 links (如果有那么一个,但我可以使所有 links 参数成为数组。

为了让它与 links 和 link 参数一起工作,我对此进行了更改:

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 属性).

您可以尝试以下与您添加的代码类似的代码。

angular.forEach(this.$filter('filter')(this.fullNav, (item) => {
    return Array.isArray(item.links) && item.links.includes(this.$location.$$path);
}, true), (item) => {
    item.active = true;
});