本文整理汇总了TypeScript中@angular/fire/firestore.AngularFirestore.collection方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AngularFirestore.collection方法的具体用法?TypeScript AngularFirestore.collection怎么用?TypeScript AngularFirestore.collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/fire/firestore.AngularFirestore
的用法示例。
在下文中一共展示了AngularFirestore.collection方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(private afs: AngularFirestore, private authService: AuthService) {
this.usersCollection = afs.collection<User>('users');
this.user = this.usersCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as User;
const id = a.payload.doc.id;
return { id, ...data };
}))
);
this.redCollection = afs.collection<Red>('red');
this.red = this.redCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as Red;
const id = a.payload.doc.id;
return { id, ...data };
}))
);
this.coorCollection = afs.collection<Coordenadas>('coordenadas');
this.coor = this.coorCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as Coordenadas;
const id = a.payload.doc.id;
return { id, ...data };
}))
);
}
示例2: if
this.afAuth.user.subscribe((auth) => {
if (auth != null) {
this.currentUser = auth.uid;
this.db.object('PERRINNTeams/' + this.currentUser).valueChanges().subscribe(snapshot => {
this.currentUserObj = snapshot;
});
afs.collection<any>('PERRINNTeams/'+this.currentUser+'/viewTeams/').valueChanges().subscribe(snapshot => {
this.currentUserTeamsObj = snapshot;
this.globalChatActivity = false;
snapshot.forEach(userTeam => {
let chatActivity:boolean=false;
if(userTeam.lastChatVisitTimestamp!=undefined)chatActivity=(userTeam.lastMessageTimestamp>userTeam.lastChatVisitTimestamp);
else if(userTeam.lastMessageTimestamp!=undefined)chatActivity=true;
else chatActivity=false;
if (chatActivity) {
this.globalChatActivity = true;
}
document.title = this.globalChatActivity ? '(!) PERRINN' : 'PERRINN';
});
});
if (this.focusUser == null) { this.focusUser = auth.uid; }
this.db.database.ref('appSettings/PERRINNServices/').once('value').then(services => {
this.services = services;
});
} else {
this.currentUser = null;
this.focusUser = null;
this.currentTeam = null;
}
});
示例3: ngOnInit
ngOnInit() {
const currentUser = this.db.collection('users', user => { return user.where('idToken', '==', 'NF1P7fzo7UYtW7MWXrIQknEVRRL2')})
.doc('customerInfo');
currentUser.valueChanges().subscribe(val => {
console.log(val)
});
}
示例4: ngOnInit
ngOnInit() {
this.rodadas = this.db.collection(config.rodadaDB).snapshotChanges()
.pipe(map(actions => {
return actions.map(a => {
const data = a.payload.doc.data() as Rodada;
console.log("atualizacao!! - " + JSON.stringify(data));
const id = a.payload.doc.id;
return { id, ...data };
});
}));
}
示例5: switchMap
switchMap((dictionary) => {
return this.afs.collection<WriteInCollaborator>(`dictionaries/${dictionary.id}/writeInCollaborators`)
.snapshotChanges().pipe(
map(arr => {
return arr.map(snap => {
const data = snap.payload.doc.data() as WriteInCollaborator;
const id = snap.payload.doc.id;
return {
id, ...data
};
});
}));
})
示例6: map
this.route.params.subscribe(params => {
this.UI.focusUser = params.id;
db.object('PERRINNTeams/' + this.UI.focusUser).valueChanges().subscribe(snapshot => {
this.UI.focusUserObj = snapshot;
});
this.viewTeams=afs.collection('PERRINNTeams').doc(this.UI.focusUser).collection('viewTeams',ref=>ref.orderBy('lastMessageTimestamp','desc')).snapshotChanges().pipe(
map(actions=>actions.map(a=>{
const values=a.payload.doc.data();
const key=a.payload.doc.id;
this.UI.loading = false;
return {key,values};
}))
);
});
示例7: setPageView
public setPageView(key): void {
const documentReference = this.afs.collection<ContentDetail>('postDetail').doc(key);
firebase.firestore().runTransaction(page => {
return page.get(documentReference.ref)
.then(doc => {
const newValue = doc.data().view + 1;
page.update(documentReference.ref, {
view: newValue
});
});
}).catch(() => {
console.log('error');
});
}
示例8: alert
this.storage.get('user').then(({ uid }) => {
this.afs.collection<User>('users')
.doc(uid)
.collection('history')
.add({ ...info })
.then(res => {
console.log(res);
})
.catch(err => {
alert(err);
})
});
示例9: incrementHitCount
route.paramMap.subscribe(async (params: ParamMap) => {
// short param is definitely defined because we can only here from the
// route with short defined
const short = params.get('short') as string;
const snapshot =
(await db.collection('links').doc<Link>(short).ref.get());
const dest = snapshot.data() as Link | undefined;
if (dest !== undefined) {
const incrementHitCount =
fns.httpsCallable<string, void>('callableIncrementHitCount');
incrementHitCount(short);
window.location.replace(dest.content);
} else {
window.location.replace(environment.baseUrl);
}
});
示例10: loginJobs
loginJobs() {
const user = this.afAuth.auth.currentUser;
const userInfo: User = {
uid: user.uid,
displayName: user.displayName,
email: user.email,
phoneNumber: user.phoneNumber,
photoURL: user.photoURL,
logged:true
}
this.afs.
collection<User>(`users`)
.doc(user.uid)
.set({ ...userInfo })
.then(res => {
console.log(res);
}).catch(err => {
alert(err)
})
this.storage.set('user', userInfo)
this.events.publish('user:login', user)
}