0
<div "ng-repeat="phone in phoneList| filter:filterPrice"> 



//custome filter 
$scope.filterPrice = function (phone) { 
     return (phone.price > MIN_VAL && phone.price < MAX_VAL);}; 

MAX_VAL 및 MIN_VAL은 입력 값이며 MAX_VAL 또는 MIN_VAL이 변경되면 phoneList를 업데이트해야합니다. 값 변경 이벤트가 발생하지만 어떻게 목록에서 업데이트합니까?사용자 정의 필터를 수동으로 호출하는 방법은 무엇입니까?

답변

1

당신이 통과 사용자에 대한 filter을 사용할 수는 필터링 minValuemaxValue 들어갔다.

<li ng-repeat="phone in phoneList | filterPrice:maxValue:minValue"> 
    {{ phone }} 
</li> 

당신이 11 번째로 PARAM에서 필터링 할 목록을 보내기는 다음 MINVALUE, maxValue를 사용하면 HTML 템플릿에서 다음 통과 한 순서에 따라. 일단 필터하면 새 목록을 반환 할 수 있습니다.

app.filter('filterPrice', function() { 
    return function(phoneList, maxValue, minValue) { 
    // You can refine this logic 
    if(!maxValue && !minValue) 
    return phoneList; 
    var filtered = []; 
    filtered = phoneList.filter(function(obj){ 
     if(maxValue && !minValue){ 
     return obj.price <= maxValue; 
     } else if(!maxValue && minValue){ 
     return obj.price >= minValue; 
     } 
     return (obj.price >= minValue && obj.price <= maxValue) 
    }) 
    return filtered; 
    }; 
}); 

Plunker

0

사용 적용 필터 형식 :

app.filter('myFilter', function() { 
    return function(input, optional1, optional2) { 
    var output; 
    // Do filter work here 
    return output; 
    } 
}); 
+0

여전히 파일러 함수를 호출하지 않는다. – jain