首先,我将向您展示我正在使用的代码。
//html code
<div *ngFor="let lis of (classes | async | classFilter)">
//component.ts code tied to the html page
constructor(public classService: ClassService) {
//just calling a service to do this:
//this._af.database.list('/Class');
this.classes =this.classService.getObservable();
}
export class ClassFilterPipe implements PipeTransform {
constructor(
public scheduleService: ScheduleService,
public UserService: UserService) {
}
transform(value: any, args?: any): any {
if(!!value)
return value.filter(value2 => {
let bool = true;
//just getting the currently logged in user so i can grab
//the key of their schedule in firebase
this.UserService.getUser().subscribe(user => {
//grab the schedule based on that key from firebase
this.scheduleService.getObjectObservable(user.schedule).subscribe(schedule => {
//schedule is just the form: {key1:true,key2:true...}
//where the keys are associated to class keys in firebase
bool = schedule.hasOwnProperty(value2.$key);
});
});
return bool;
});
}
}
基本上我要做的是从Firebase显示特定用户的类。所以我现在要做的是获取所有类的列表然后使用管道转换我将使用来自用户的数据过滤将在页面上显示的数据。我遇到了麻烦,因为我需要使用这些信息来过滤我需要从Firebase中获取的类。因此,它存在异步获取该信息的问题。我不知道是否有一种方法可以在我拥有其他数据或我可以做的事情后过滤数据。如果有人对如何过滤我的数据有任何想法,请告诉我。谢谢!