我知道有一个管道的概念,但要让管道工作,它应该拥有所有数据。
我正在使用 Angular 服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Patient } from '../shared/patient';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import 'rxjs/add/operator/map';
@Injectable()
export class PatientService {
private serviceUrl = 'someUrl';
private patients = new BehaviorSubject<Patient[]>(null);
constructor(private http: HttpClient) {
this.http.get<Patient[]>(this.serviceUrl);
// .subscribe(data => { console.log(data); });
}
/*
* Get list of all patients
*/
getPatient(): Observable<Patient[]> {
return this.http.get<Patient[]>(this.serviceUrl);
}
selectPatient(patients: Patient[]) {
this.patients.next(patients);
// return this.patients.asObservable;
}
getSelectedPatient(): Observable<Patient[]> {
return this.patients.asObservable();
}
}
这是所有“搜索”发生的地方:
<table>
<thead>
<tr>
<th><input type="checkbox" id="check-all" (click)="checkall()"></th>
<th>Patient Name</th>
<th>Patient ID</th>
<th>NHS</th>
<th>MPI</th>
<th>HID</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let patient of patients | patientFilter:filter; let i = index" [class.active]="i == selectedRow">
<td><input type="checkbox" class="checkbox" (click)="uncheckall();"></td>
<td>{{ patient.firstName }} {{ patient.middleName }} {{patient.lastName}}</td>
<td>{{ patient.pid }}</td>
<td>{{ patient.nhs }}</td>
<td>{{ patient.mpi }}</td>
<td>{{ patient.hid }}</td>
</tr>
</tbody>
</table>
这是我在打字稿文件中使用的方法,它将在加载 html 页面时获取所有患者列表:
ngOnInit() {
this.patientService.getPatient().subscribe(
(patients: Patient[]) => { this.patients = patients;});
}
有没有有效的方法/方法来应用过滤器?