Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript core.js:6150 ERROR-TypeError:this.object在角度上不可编辑_Javascript_Angular_Firebase_Google Cloud Firestore_Angularfire2 - Fatal编程技术网

Javascript core.js:6150 ERROR-TypeError:this.object在角度上不可编辑

Javascript core.js:6150 ERROR-TypeError:this.object在角度上不可编辑,javascript,angular,firebase,google-cloud-firestore,angularfire2,Javascript,Angular,Firebase,Google Cloud Firestore,Angularfire2,我想在HTML文件中显示用户的名字 getFirstName(id: any){ this.users = this.afs.collection('users', ref => ref.where("uid", "==", id)).valueChanges(); this.users.subscribe(users => { this.users = users; }) let fname;

我想在HTML文件中显示用户的名字

  getFirstName(id: any){
    this.users = this.afs.collection('users', ref => ref.where("uid", "==", id)).valueChanges();

    this.users.subscribe(users => {
      this.users = users;
    })
    let fname;
    for(let user of this.users){
        fname = user.firstName;
    }
    return fname;
  }
但当名字显示在HTML中时,编译器会出错

core.js:6150 ERROR TypeError: this.users is not iterable

不要使用与订阅对象和数据相同的变量this.users。您还需要在订阅中使用for of

fname  = null;

  getFirstName(id: any){
    this.users = this.afs.collection('users', ref => ref.where("uid", "==", id)).valueChanges();

    this.users.subscribe(users => {
      for(let user of users){
        this.fname = user.firstName;
      }
    })
  }