javascript - 错误 : '[object Object]' of type 'object' . NgFor 仅支持绑定(bind)到 Iterables,例如 Arrays。 - ionic 项目

标签 javascript angular typescript ionic-framework single-page-application

我正在尝试使用 Ionic 和 AngularFire 从 Firebase Firestore 数据库中获取用户的用户名。我正在使用 valueChanges() 方法获取可观察对象,然后尝试使用异步管道解释可观察对象。但是,当我运行代码时,出现以下错误:

error

但是,当我记录 observable 时,它​​显示如下:

observable

个人资料.page.ts:

import { Component, OnInit } from '@angular/core';

import { AngularFireAuth } from '@angular/fire/auth';
import { Router } from '@angular/router';

import { UserService } from '../user.service'

import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore'

import { Observable } from 'rxjs';

@Component({
  selector: 'app-profile',
  templateUrl: './profile.page.html',
  styleUrls: ['./profile.page.scss'],
})

export class ProfilePage implements OnInit {





  constructor(public afAuth: AngularFireAuth, public router: Router, public user: UserService, public db: AngularFirestore) { 


  }



  ngOnInit() {



  }

  logout() { this.afAuth.auth.signOut(); this.router.navigate(['/login']);}


}

个人资料.page.html:

 <ion-content>
  <ion-grid>
      <ion-row justify-content-center align-items-center style="height: 50%">
    <ion-button color="danger" size="small" shape="round" (click)="logout()">Logout</ion-button>
    <p *ngFor="let users of (username | async)">{{ users.username }}</p>
    </ion-row>
    </ion-grid>
</ion-content>  

在此先感谢您的帮助。

最佳答案

你有这个错误是因为你的用户名数据不是一个数组所以我建议你像这样更改你的代码。使您的用户名成为一个数组,然后将其插入数组

username: string[] = [];

this.username = this.username.push(users.valueChanges());

关于javascript - 错误 : '[object Object]' of type 'object' . NgFor 仅支持绑定(bind)到 Iterables,例如 Arrays。 - ionic 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58108519/

相关文章:

javascript - Chrome 中收到 "decodeAudioData error null"

Javascript appendChild() 调用在 IE 中不起作用

angular - 如何在 Angular 2 中使用输入标签文件类型重置所选文件?

javascript - 使用 require.js 加载命名的 TypeScript 模块

javascript - 从数组中查找所有可能的匹配字符串和子字符串

javascript - gulp 相关任务 - browserify 和预浏览任务

javascript - 无法使用 requirejs 获取对 ACE 的引用

Angular 7 (RxJs 6.x) - 如何使用 throwError

angular - 将 ngModel 值重置为默认模型?

angular - 使用切片管道后如何连接字符串