我想问一下我的订阅方法。我想从 firebase 中获取我的对象(员工)并对我的对象进行大量操作,例如平均工资、平均缺勤天数……在我看来,这看起来太可怕了。我的服务无效:
getEmployees(): Observable<Employee[]> {
return this.db.list<Employee>(this.Api_url).snapshotChanges()
.pipe(map(response => response.map(car => this.assignKey(car))));
}
Run Code Online (Sandbox Code Playgroud)
还有我的 ngOnInit:
ngOnInit() {
this.subscribtion = this.mainservice.getEmployees().subscribe((emps)=> {
this.employees = emps;
this.workersdatas = [];
this.educationdatas = [];
this.checkavaragesalaries(emps);
this.countMonthAbsences(emps, 1);
this.countMonthSalaries(emps, 1);
this.departments.forEach((one)=> {
const dep = emps.filter(on => on.department.includes(one) && this.FilterEmployees(on)).length;
this.workersdatas.push({name: one, value: dep});
});
this.educations.forEach((one)=> {
const edu = emps.filter(on => on.education.includes(one)).length;
this.educationdatas.push({name: one, value: edu});
});
const mynumb =this.educationdatas.map(on => on.value);
this.mosteducation = this.educationdatas.filter(one => one.value === Math.max(...mynumb))[0].name;
}); }
Run Code Online (Sandbox Code Playgroud)
我应该在 ngOnDestroy …