2017-12-15 6 views
0

angularjs 필터를 만들려고합니다. 나는 세 가지 특성을 필터링하고있다. 처음 두 개는 비교기 false이고 마지막 것은 비교기 true입니다. 사용자 정의 필터를 만들지 않고도 가능합니까? 아래에서 시도했지만 오류가 발생합니다.복수 필터가있는 비교기를 사용하는 angularjs 필터

|

filter : 
    { 
     'PatientFullName' : vm.headerService.searchText, 
     'Archived' : vm.headerService.Archived, 
     'PhysicianID' : {vm.headerService.selectedPhysician.PhysicianID,true} 
    } 

여기 여기 오류

angular.js:14794 Error: [$parse:syntax] Syntax Error: Token '.' is unexpected, expecting [}] at column 263 of the expression [vm.patientlist | orderBy: vm.headerService.currentSort.orderBy:vm.headerService.currentSort.sortDescending | filter : { 'PatientFullName' : vm.headerService.searchText, 'Archived' : vm.headerService.Archived, 'PhysicianID' : {vm.headerService.selectedPhysician.PhysicianID,true} }] starting at [.headerService.selectedPhysician.PhysicianID,true} }].

답변

1

{vm.headerService.selectedPhysician.PhysicianID,true}가 올바른 개체가 아닙니다입니다 전체 HTML

<div class="col-sm-6 col-md-4" ng-repeat="patient in vm.patientlist | orderBy: vm.headerService.currentSort.orderBy:vm.headerService.currentSort.sortDescending 
    | filter : 
    { 
     'PatientFullName' : vm.headerService.searchText, 
     'Archived' : vm.headerService.Archived, 
     'PhysicianID' : {vm.headerService.selectedPhysician.PhysicianID,true} 
    }"> 

입니다. 당신이 체인 필터링을 할 수있다 comparator의 다른 값으로 필터링을 수행하려면 :

<div class="col-sm-6 col-md-4" ng-repeat="patient in vm.patientlist | orderBy: vm.headerService.currentSort.orderBy:vm.headerService.currentSort.sortDescending 
| filter : 
{ 
    'PatientFullName' : vm.headerService.searchText, 
    'Archived' : vm.headerService.Archived 
} 
| filter : 
{   
    'PhysicianID' : vm.headerService.selectedPhysician.PhysicianID 
}: true"> 

그러나 더 나은 컨트롤러의 방법으로 그 재 작성. 가독성이 향상됩니다.

<div class="col-sm-6 col-md-4" 
ng-repeat="patient in vm.patientlist | 
      orderBy: vm.headerService.currentSort.orderBy 
        : vm.headerService.currentSort.sortDescending 
      |filter : vm.myFilteringMethod">