过滤变量可能的范围问题

时间:2016-01-22 23:20:20

标签: angularjs angularjs-scope angularjs-filter

我正在尝试做类似于this question正在做的事情,获取过滤结果的长度和总数。

HTML:

<div ng-app="app" ng-controller="controller">
  <div class="col-md-4 ">Filter: <input class="form-control" ng-model="dataFilter" placeholder="filter" /></div>
  <div class="col-md-4 ">Total:  {{filtered.length}}</div>
  <table class="table table-hover" ts-wrapper>
    <thead>
      <tr>
        <th ts-criteria="policy.policy_number | parseInt">
          Policy
        </th>
        <th ts-criteria="sales_rep.name">
          Sales Rep
        </th>
        <th ts-criteria="policy.customer.full_name">
          Customer
        </th>
        <th ts-criteria="type">
          Type
        </th>
        <th ts-criteria="change_amt | parseFloat">
          Change Amount
        </th>
        <th ts-criteria="effective_date | date">
          Effective Date {{filtered.length}}
        </th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="transaction in filtered = (data | filter: dataFilter )" ts-repeat>
        <td>{{transaction.policy.policy_number}}{{pizza}}</td>
        <td>{{transaction.sales_rep.name}}</td>
        <td>{{transaction.policy.customer.full_name}}</td>
        <td>{{transaction.transaction_type}}</td>
        <td>${{transaction.change_amt | number:currency}}</td>
        <td>{{transaction.effective_date | date}}</td>
      </tr>
    </tbody>
  </table>
</div>

JS真的没有什么特别的。在上面的示例中,{{filtered}}在表格中显示了预期的过滤结果(在本例中为<th>)。当我试图在div中获得长度时,它什么都不返回。

这里是否创建了某种孤立的范围?我的代码似乎与我上面链接的SO问题的示例相匹配,那么为什么他们可以在其他元素中访问该变量而我不能?

0 个答案:

没有答案
相关问题