无法从angular和firebase2中的对象获取属性值

时间:2017-10-24 13:02:37

标签: typescript firebase firebase-realtime-database angularfire2

为什么我无法从对象获取不同的属性值? 我实际上是关注一个在构造函数中初始化变量客户端的材料,如下所示。

@Injectable()
export class ClientService {

  clients: FirebaseListObservable<any[]>;
  client: FirebaseObjectObservable<any>;

  constructor(
    public af: AngularFireDatabase
  ) { 
    this.clients = this.af.list('/clients') as FirebaseListObservable<Client[]>;
  }

  getClients(){
    return this.clients;
  }
}

getClients()方法用于ClientComponent的ngOnInit()方法。

export class ClientsComponent implements OnInit {

  clients: Client[];

  constructor(
    public clientService: ClientService
  ) { }


  ngOnInit() {
    this.clientService.getClients().subscribe(clients => {
      this.clients = clients;
      console.log(this.clients);
    })
  }

}

现在,我试图通过循环遍历客户端细节。

enter image description here 我可以在控制台日志中看到该对象,但数据未显示在前端。 enter image description here

0 个答案:

没有答案