简体   繁体   English

角度滤镜在使用ng-if时不起作用

[英]Angular filter having no effect when using ng-if

I seem to be missing something here with filtering an ng-repeat with a search box. 我似乎在这里缺少用搜索框过滤ng-repeat的功能。

<li ng-if="searchTab"><input type="text" class="form-control" placeholder="Search"  ng-model="search" >
  </li>

and the ng-repeat 和ng-repeat

<div dir-paginate="saving in savings| orderBy:orderByField:!reverseSort| filter:search | filter:{retailer:filterBy}|itemsPerPage:10" class="list-group-item">

is there any obvious reason why the filter doesnt do anything when i type in the search box? 有什么明显的原因为什么我在搜索框中键入内容时过滤器什么都不做?

Edit - I notice that if i remove the ng-if it works. 编辑-我注意到,如果我删除ng-如果它可以工作。 Is there any way of using both? 有什么办法可以同时使用两者吗?

If the value for searchTab is false during the initialisation phase of the controller then the input div is not evaluated. 如果在控制器的初始化阶段searchTab的值为false,则不评估输入div。 Hence the ng-model directive wont create the variable 'search' on the controller scope. 因此,ng-model指令不会在控制器范围内创建变量“ search”。 So please declare 'search' as a variable in your controller. 因此,请在控制器中将“搜索”声明为变量。

Instead of using ng-if use ng-show. 而不是使用ng-if,请使用ng-show。

<li ng-show="searchTab"><input type="text" class="form-control" placeholder="Search"  ng-model="search" >
  </li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM