AngularFire2 ngrx / effects通过id无法正常工作

时间:2017-12-23 04:28:50

标签: angularfire2 google-cloud-firestore ngrx-effects

如何使用文档的ID从firestore中的集合中获取文档。

snapshotChanges和valueChanges可用,但我未定义doc.data()

@Effect()
    queryDetails$: Observable<Action> = this.actions$.ofType(speakerActions.QUERY_DETAILS)
        .map((action: speakerActions.QueryDetails) => action.payload)
        .mergeMap(action => {
            const ref: AngularFirestoreDocument<User> = this.afs.doc<User>(`users/${action}`)
            return ref.snapshotChanges()
        })
        .map(snapshot => {
            if(snapshot.payload) {
                console.log(`SpeakerEffects :: queryDetails : ${snapshot.payload.id}`)
                return {
                    type: `[Speaker] modified`,
                    payload: { id: snapshot.payload.id, ...snapshot.payload.doc.data() }
                }
            }
        })

&#39;用户&#39;对象接口详细信息如下:

export class User {

    id: string;

    name: string;
    email: string;

    about: string;

    emailVerified?: boolean;

    reader: boolean;
    author?: boolean;
    admin?:  boolean;

    roles: Roles;

    loading?: boolean;

    constructor(authData) {
        this.id         = authData.uid
        this.email      = authData.email
        this.photoURL   = authData.photoURL
        this.roles      = { reader: true }
    }
}

有效负载ID在控制台中打印,但数据&#39;显示未定义。

有什么想法吗?

0 个答案:

没有答案