我是使用angularfire2的新手。可以说,我想列出每个项目,但我也希望使用* ngFor获取配置文件的名称。但是,我有这个错误:
无法找到不同的支持对象'[object Object]'的类型 '宾语'。 NgFor仅支持绑定到Iterables,例如Arrays。
我有这种数据
- items
- id
- name: string
- type : string
- userId: string
- profile
- id
- username: string
这是我的代码
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { Item } from '../../models/item';
import { profile } from '../../models/profile';
import { AngularFireDatabase } from 'angularfire2/database';
@IonicPage()
@Component({
selector: 'page-timeline',
templateUrl: 'timeline.html',
})
export class TimelinePage {
item = {} as Item ;
userId : string;
profile = {} as Profile;
items: Observable<any[]>;
profile: Observable<any[]>;
constructor(
private afDatabase : AngularFireDatabase,
public navCtrl: NavController,
public navParams: NavParams) {
this.afDatabase.object(`profile/${c.payload.val().userId}`)
this.dataItem = this.afDatabase.list('items' );
this.dataProfile = this.afDatabase.list('profile/');
}
ngOnInit(){
this.items = this.dataItem.snapshotChanges().map(items => {
return this.items.map(item => {
this.item.userId.map(profile => {
this.dataProfile.subscribe(c => {
profile = c;
//console.log(profile);
});
});
return this.items;
});
});
console.log(this.items)
}
}
我的HTML代码
<ion-list color="primary">
<ion-item *ngFor="let item of items | async">
<h2>{{item.name}}</h2>
<p>{{item.type}}</p>
<p>{{item.username}}</p>
<button ion-button clear item-end>View</button>
</ion-item>
</ion-list>
谢谢