-1

我有一個輸入類型搜索的元素。我無法對此應用過濾器。Angular JS Filter沒有在ng-repeat中應用

<label class="item-input-wrapper" style="font-size:20px!important;"> 
    <i class="icon ion-ios-search placeholder-icon"></i> 
    <input type="search" style="width:45%;font-size:20px!important;" placeholder=" Search" ng-model="searchText.text"> 
</label> 

在這裏,在這種情況下,過濾器沒有被應用,在那裏,如果我不使用ng-if,我能申請過濾器。請幫忙,因爲我不想刪除ng-if,因爲我有理由保留它。

<div class="w-clearfix product-row" ng-show="isListViewShown" **ng-repeat="product in arrayOfProducts | 
     filter : searchText.text " ng-if="$index % 4 === 0">** 
         <div class="_4-col" ng-if="$index < 
     arrayOfProducts.length"> 
          product.name 

    </div> 
</div> 

回答

1

試試看這會否對您有所幫助?

angular.module('myApp', []).controller('ctrl', function($scope) { 
 

 
$scope.searchText = ''; 
 

 
$scope.names = ['India','America','Japan','Denmark','Russia','Landon','Cuba','Finland','Italy','Shrilanka','Australia','Brazil','Canada']; 
 
}); 
 
<html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
<body> 
 
<div ng-app="myApp" ng-controller="ctrl"> 
 
<input type="search" ng-model="searchText" /> 
 
<ul> 
 
    <li ng-repeat="x in names | filter : searchText" ng-if="$index % 4 === 0"> 
 
    {{ x }} 
 
    </li> 
 
</ul> 
 
</div> 
 

 

 
</body> 
 
</html>

相關問題