如何使用指令作为过滤器?

时间:2015-08-12 03:11:42

标签: angularjs filter

我必须使用我想要使用相同指令过滤的数据分隔列表:

  .directive('myFilter', function ($filter) {
        return {
            restrict: 'E',
            templateUrl: 'my-dialog.html',
            link: function ($scope) {
                $scope.lov_state = [
                    {'lookupCode': 'AL', 'description': 'Alabama'},
                    {'lookupCode': 'FL', 'description': 'Florida'},
                    {'lookupCode': 'CA', 'description': 'California'},
                    {'lookupCode': 'DE', 'description': 'Delaware'}
                ];
            }
        };
    });

页面如下所示:

  <my-filter></my-filter>

  <ul>
    <li ng-repeat="item in data | filter:address.state">
      {{item.name}}
    </li>
  </ul>


  <my-filter></my-filter>

  <ul>
    <li ng-repeat="item in data2 | filter:address.state">
      {{item.name}}
    </li>
  </ul>

</div>

目前,过滤器同时适用于ul?我需要更新什么以确保过滤器可以独立地运行两个列表?

plunkr:http://plnkr.co/edit/eNgvIJwhNAXrizR4yevc?p=preview

0 个答案:

没有答案