【问题标题】:Filter AngularJS without using ngOptions or ngRepeat在不使用 ngOptions 或 ngRepeat 的情况下过滤 AngularJS
【发布时间】:2015-06-19 08:10:04
【问题描述】:

有没有什么方法可以在不使用 AngularJS 中的 ng-repeat 或 ngOptions 的情况下通过角度过滤器($filter)过滤选择框。

我有一个这样写的选择选项代码:

<select>
   <option value="one">one</option>
   <option value="two">two</option>
   <option value="three">three</option>
</select>

还有一个输入框,用于过滤选项中的内容:

<input ng-model="myFilter">

【问题讨论】:

  • &lt;select ng-model="myFilter"&gt; :)
  • 我能知道你为什么不应该使用 ng-options/ng-repeat 吗?虐待狂? :)
  • 我在数组中没有我的选项。 n 即使我将它们放在一个数组中,也不要将它们设置为使用 ngOptions 或 ngRepeat 所需的格式

标签: angularjs filter


【解决方案1】:

您可以将 ng-if 与函数一起使用。

<option ng-if="checkFilter('group1')" value="one">

然后在你的控制器中

function checkFilter(value) {
  return myFilter.filter(function (element) { return element == value }); 
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多