我怎样才能获得一个角度和的结果数组QUOT

我怎样才能获得一个角度和的结果数组QUOT

本文介绍了我怎样才能获得一个角度和的结果数组QUOT; |过滤"在变量前pression?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在角度,你可以写过滤前pressions像

In angular, you can write filter expressions like

<input type="text" ng-model="query">

<table>
    <tr ng-repeat="phone in phones | filter: query">
       <td>{{phone.vendor}}</td>
       <td>{{phone.model}}</td>
    </tr>
</table>

和将更新表,只显示匹配查询哪个您进入输入文本手机

and it will update the table to show only the phones which match the query text you enter into the input.

我怎样才能过滤器,例如对应的结果数组当前显示,在一个变量 [电话对象] S(例如一个范围的变量)?

How can I get the corresponding result array of the filter, e.g. the [phone object]s that are currently displayed, in a variable (e.g. a scope variable)?

推荐答案

实际上,你可以在一个角前pression分配新变量的范围。所以,最简单的办法是做&LT; TR NG重复=手机(filteredPhones =(手机|过滤器:查询))&GT; 。 filteredPhones现在是在当前范围内的变量 - 见

You can actually assign new variables to the scope in an angular expression. So the simplest solution would be to do <tr ng-repeat="phone in (filteredPhones = (phones | filter: query))">. filteredPhones is now a variable in the current scope - see this plnkr example.

这篇关于我怎样才能获得一个角度和的结果数组QUOT; |过滤&QUOT;在变量前pression?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:40