【问题标题】:In ionic how to read and display the information from firestore在离子中如何读取和显示来自firestore的信息
【发布时间】:2019-11-23 00:05:30
【问题描述】:

在 ionic 中,我想从 firestore 的特定字段(例如 Name 那里)获取和显示信息,但问题是它也显示其他文档的字段 Names。

ngOnInit(){
   this.authService.readc().subscribe(data => {

   this.datas = data.map(e => {
     return {
     Name: e.payload.doc.data()['Name'],
    };
  })
    console.log(this.datas);
  });
}
}

name() {

    var counter = this.firestore.doc(`info/${this.authService.userDetails().uid}`);
    counter.set({
      Name: this.Name
    })
  }

在 authService 中

readc() {
    return this.firestore.collection('info').snapshotChanges();
}

【问题讨论】:

    标签: firebase ionic-framework google-cloud-firestore ionic4


    【解决方案1】:

    可能是这样的吗?

    home.page.ts

    export class HomePage {
    
      names: any;
    
      constructor(auth: AuthService) {
        auth.readc().subscribe(data => {
          this.names = data.map(person => ({ name: person.name }));
        });
      }
    }
    

    auth.service.ts

    export class AuthService {
    
      people: any;
    
      constructor(db: AngularFirestore) {
        this.people = db.collection('people').valueChanges();
      }
    
      readc(){
        return this.people;
      }
    }
    

    查看angularfire docs,了解有关在 Firebase 中使用集合和文档的更多详细信息。

    希望这会有所帮助。

    【讨论】:

    • 嗨,谢谢你帮助我这里是问题解释请帮助我 - stackoverflow.com/questions/57043952/…
    • registerUser(value){ firebase.auth().createUserWithEmailAndPassword(value.email, value.password) this.firestore.doc(users/${value.email}).set({ email: value.email, } )
    • 这就是我设置文档的方式
    猜你喜欢
    • 2020-03-13
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多