Firestore에서 특정 필드의 값을 가져오는 가장 쉬운 방법(Angular)
소개
Firebase Firestore에서 특정 필드의 값 가져오기(Angularfire)
이 기사에서 쓴 것처럼 특정 필드의 값을 얻는데 상당히 고전한 경험이 있다. . .
그러나 어쩌면 이번에는 순조롭고 똑똑한 코드로 만들어졌습니다 
왜 전에는 이렇게 고생했을까? ? ? (알고있는 사람, 말해주세요 · ·)
실현하고 싶은 일

이런 식으로 Firestore에 데이터가 들어갔다면 원하는 데이터는 user의 필드이다 isLocked
값!
이 녀석을 얻으려면 어떻게해야합니까?
환경
Angularfire이 프로젝트에 있음
필드 값 얻기
※필요 최소한의 코드입니다
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
export class SettingsPage implements OnInit {
isLocked;
constructor(
private afAuth: AngularFireAuth,
private db: AngularFirestore,
) {}
ngOnInit() {
this.afAuth.auth.onAuthStateChanged((user) => {
if (user != null) {
const userRef = this.db.collection('users').doc(user.uid);
userRef.get().subscribe(docSnapshot => {
// get('isLocked')でフィールド名を指定
const locked: boolean = docSnapshot.get('isLocked');
console.log('ロックされていますか? ' + locked);
this.isLocked = locked;
});
}
});
}
}
이제 users/uid/
에 있는 isLocked
라는 값(여기서는 true 또는 false)을 얻을 수 있었습니다!
Reference
이 문제에 관하여(Firestore에서 특정 필드의 값을 가져오는 가장 쉬운 방법(Angular)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kokogento/items/138b2b93cdf285fee3fa
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)

이런 식으로 Firestore에 데이터가 들어갔다면 원하는 데이터는 user의 필드이다
isLocked
값!이 녀석을 얻으려면 어떻게해야합니까?
환경
Angularfire이 프로젝트에 있음
필드 값 얻기
※필요 최소한의 코드입니다
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
export class SettingsPage implements OnInit {
isLocked;
constructor(
private afAuth: AngularFireAuth,
private db: AngularFirestore,
) {}
ngOnInit() {
this.afAuth.auth.onAuthStateChanged((user) => {
if (user != null) {
const userRef = this.db.collection('users').doc(user.uid);
userRef.get().subscribe(docSnapshot => {
// get('isLocked')でフィールド名を指定
const locked: boolean = docSnapshot.get('isLocked');
console.log('ロックされていますか? ' + locked);
this.isLocked = locked;
});
}
});
}
}
이제 users/uid/
에 있는 isLocked
라는 값(여기서는 true 또는 false)을 얻을 수 있었습니다!
Reference
이 문제에 관하여(Firestore에서 특정 필드의 값을 가져오는 가장 쉬운 방법(Angular)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kokogento/items/138b2b93cdf285fee3fa
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
※필요 최소한의 코드입니다
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
export class SettingsPage implements OnInit {
isLocked;
constructor(
private afAuth: AngularFireAuth,
private db: AngularFirestore,
) {}
ngOnInit() {
this.afAuth.auth.onAuthStateChanged((user) => {
if (user != null) {
const userRef = this.db.collection('users').doc(user.uid);
userRef.get().subscribe(docSnapshot => {
// get('isLocked')でフィールド名を指定
const locked: boolean = docSnapshot.get('isLocked');
console.log('ロックされていますか? ' + locked);
this.isLocked = locked;
});
}
});
}
}
이제
users/uid/
에 있는 isLocked
라는 값(여기서는 true 또는 false)을 얻을 수 있었습니다!
Reference
이 문제에 관하여(Firestore에서 특정 필드의 값을 가져오는 가장 쉬운 방법(Angular)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kokogento/items/138b2b93cdf285fee3fa텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)