我正在尝试对从Firebase提取的数据进行一些过滤。
我试图通过获取完整数据并使用HTML中的 ngIf 进行过滤来做到这一点。
这是我的 public abstract class A<T, TB, C, D>
where T : class
where C : FooParameter
where D : FooResponse
where TB : B<C,D> {
public TB B { get; set; }
public A()
{
//instantiate B property
}
}
文件
list.ts
您看到的是在这里获取数据
import { Component, OnInit, OnDestroy } from '@angular/core';
import { DressService, Dress, City } from '../services/dress.service';
import { LanguageService } from '../services/language.service';
import { AuthService } from '../services/auth.service';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-list',
templateUrl: 'list.page.html',
styleUrls: ['list.page.scss']
})
export class ListPage implements OnInit, OnDestroy{
dress: Dress[];
mySub: Subscription;
needApproval = null;
currentCity = 'all';
city: City[];
citySub: Subscription;
constructor(private dressService: DressService,
public languageService: LanguageService,
private authService: AuthService,
private router: Router,
) { }
ngOnDestroy() {
this.mySub.unsubscribe();
this.citySub.unsubscribe();
this.needApproval = null;
console.log('list page destroyed');
// tslint:disable-next-line: forin
for (const member in this.dress) { delete this.dress[member]; }
}
changeFilter() {
console.log(this.currentCity);
}
ngOnInit() {
console.log('starting list page');
this.mySub = this.dressService.getDresses().subscribe(res => {
this.dress = res;
console.log(typeof (this.dress));
for (const key in this.dress) {
if (this.dress.hasOwnProperty(key)) {
if (!this.dress[key].active) {
const currentNeedApproval = this.needApproval;
const addedNeedApproval = 1;
const newNeedApproval = Number(currentNeedApproval) + Number(addedNeedApproval);
this.needApproval = newNeedApproval;
}
}
}
});
this.gettingData();
}
getCurrentUser() {
return this.authService.userDetails();
}
getCurrentLanguage() {
return this.languageService.getCurrentLanguage();
}
changeToArabic() {
this.languageService.changeToArabic();
}
changeToEnglish() {
this.languageService.changeToEnglish();
}
gettingData() {
this.citySub = this.dressService.getCities().subscribe(res => {
this.city = res;
console.log(this.city);
});
}
}
然后将其添加到要在我的HTML文件中使用的变量中
这是我的HTML文件:
this.mySub = this.dressService.getDresses().subscribe(res => {
this.dress = res;
我这里有一个选择菜单,该菜单从添加到项目详细信息的同一源获取数据,然后我使用ngIf条件过滤查看的项目。
一旦我更换了城市,它什么也没显示。