我正在使用
我想要实现的目标
问题
我的项目列表解析器
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { AuthService } from '../../user/auth.service';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import 'rxjs/add/operator/first';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class ProjectsListResolver {
constructor(private database: AngularFireDatabase, private authService: AuthService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
return Observable.create(observer => {
this.authService.user
.first()
.subscribe(user => {
this.database.list(`/project_list/${user.uid}`)
.first()
.subscribe(projectList => {
observer.next(projectList);
observer.complete();
});
});
});
}
}
项目组件TS
ngOnInit() {
// Returns the data from the projects list resolver
this.activatedRoute.data
.subscribe((
data: { projectListData: any }) => {
this.projectsList = data.projectListData;
});
}
非常感谢任何帮助!
答案 0 :(得分:0)
我用我的申请做到了。首先,当您从Firebase获取数据时,它是json,因此您必须将其更改为数组,然后您必须根据日期对数组进行排序。这是排序功能:
arr.sort((a: any [], b: any []) => {
return (new Date (a[0]) .getTime() - new Date (b[0]).getTime()) ;
});
如果你想要完整的代码,我可以发布它。