试图从我的路由器中解析来自 angularfire2 的一些数据。当我通过它时,return of('Hello Alligator!')
我的组件日志Hello Alligator
但是当我尝试从 angularfire 服务中解析数据时,它只是挂起并且永远不会解析。我还想将它设置在我仍然可以添加到集合中的位置。我究竟做错了什么?
//SmsListResolverService
import {Resolve, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'
import {Observable, of} from 'rxjs'
import { SMS } from './SMS.interface';
import {FirebaseService} from '../_shared/firebase.service'
import { Injectable } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
@Injectable()
export class SmsListResolverService implements Resolve<Observable<any>>{
constructor(private db:AngularFirestore){
}
resolve(){
// this_works-----> return of('Hello Alligator!')
return this.db.collection('messages').valueChanges() //not this
}
}
//Route module
export const routes: Routes = [
{
path: 'chat',
component: SmsComponent,
resolve: { messages: SmsListResolverService }
}
];
//component
export class SmsComponent{
constructor(public sms: SmsService, private route:ActivatedRoute) {
console.log(this.route.snapshot.data)
}