Javascript AngularJS:过滤器阵列

Javascript AngularJS:过滤器阵列,javascript,angularjs,Javascript,Angularjs,我为包含数据的表创建了一个元素指令。该表使用ng repeats呈现所有行/列 我为元素指令创建了一个属性指令。它的目的是获取不希望包含在表中的列。完整指令可能如下所示: <extended-table exclude="columnone, columntwo"></extended-table> 如果列包含在$scope.exclude数组中,如何使标题和行的ng repeat忽略列 app.filter('startFrom', function () {

我为包含数据的表创建了一个元素指令。该表使用
ng repeat
s呈现所有行/列

我为元素指令创建了一个属性指令。它的目的是获取不希望包含在表中的列。完整指令可能如下所示:

<extended-table exclude="columnone, columntwo"></extended-table>
如果列包含在
$scope.exclude
数组中,如何使标题和行的
ng repeat
忽略列

app.filter('startFrom', function () {
    return function (input, start) {
        start = +start;
        return input.slice(start);
    };
});

我的建议是通过
扩展表
指令读取
exclude
属性,而不是创建自定义指令来执行此操作

下面是一些不完整的代码,说明了如何做到这一点:

myModule.directive('extended-table', function() {
    return {
...
      scope: {
        'exclude': '@' // This says to load the attribute 'exclude' into a scope property of the same name.
      }
...
    // In your link functions you could process the scope.exclude property as you wish.
    };
  });
有关更多信息,请访问:

这种方法的最大优点是,您不会创建两个相互依赖的指令

注:

使用
@
绑定时,请记住使用
{{}
符号传递属性:

    <myDirective myDirectiveAttribute="{{someProperty}}"/>


ng repeat有一个可以使用的过滤器属性。如果要对多个值进行筛选,可以添加问题中所回答的逻辑:当我这样做时,在作用域上记录console.log exclude属性,它可以工作,但它会中断从筛选开始的
startFrom。我不知道为什么。
过滤器开始?我不确定我是否理解。我想我可能需要看更多的代码来了解您是如何使用
startFrom
过滤器的。还为我的答案添加了一个编辑。
myModule.directive('extended-table', function() {
    return {
...
      scope: {
        'exclude': '@' // This says to load the attribute 'exclude' into a scope property of the same name.
      }
...
    // In your link functions you could process the scope.exclude property as you wish.
    };
  });
@ – binds the value of parent scope property (which always a string) to the local scope. So the value you want to pass in should be wrapped in {{}}. Remember `a` in braces.
= – binds parent scope property directly which will be evaluated before being passed in.
& – binds an expression or method which will be executed in the context of the scope it belongs.
    <myDirective myDirectiveAttribute="{{someProperty}}"/>