*ng for未呈现DOM,但正在调用firebase数据
我使用下面的代码从firebase获取数据,并且我能够使用下面的代码创建一个数组*ng for未呈现DOM,但正在调用firebase数据,firebase,angular,Firebase,Angular,我使用下面的代码从firebase获取数据,并且我能够使用下面的代码创建一个数组 fetchPeopleFromFirebase(){ Firebase fbUsers = this.fbObject.child("posts"); fbUsers.once("value", (snapshot) => { if(snapshot.exists()) { snapshot.forEach((object) =>
fetchPeopleFromFirebase(){
Firebase fbUsers = this.fbObject.child("posts");
fbUsers.once("value", (snapshot) => {
if(snapshot.exists()) {
snapshot.forEach((object) => {
console.log("Current Post");
console.log(object.val());
Firebase fbUserDetails = this.fbObject.child("users");
var createdById = object.child('createdBy/_id').val();
console.log("Checking for : " + createdById)
fbUserDetails.child(createdById).once("value", (snapshot) => {
if(snapshot.exists()) {
console.log(snapshot.val());
}
});
this.posts.push(object.val());
});
}
console.log("firebase Data",this.posts);
}
}
我将数据存储在this.posts中,并尝试在视图中使用它,如:
*ng-for="#post of posts"
但在控制台上打印数据时,它不会显示任何内容
有人能帮我吗
编辑:
<ion-content>
<ion-card *ng-for="#post of posts">
<ion-item>
<ion-avatar item-left>
<img src="{{post.createdBy.avatarUrl}}">
</ion-avatar>
<h2>{{post.createdBy.firstName}} {{post.createdBy.lastName}}</h2>
<p>{{post.createdBy.profession}}</p>
</ion-item>
<ion-item>
<ion-list-header>{{post.title}}</ion-list-header>
<img src="{{post.image}}">
</ion-item>
<ion-card-content>
<p>{{post.description}}.</p>
</ion-card-content>
<ion-item actions class="demo-card">
<button primary clear item-left (click)="openLikesFollowers()">
<icon thumbs-up></icon>
<div>5 followers</div>
</button>
<button primary clear item-left (click)="openLikesFollowers()">
<icon text></icon>
<div>4 Comments</div>
</button>
<p item-left class="time-ago">
61 views
</p>
</ion-item>
<ion-item actions>
<p item-left class="time-ago">
+5 collegues are following this
</p>
</ion-item>
</ion-card>
</ion-content>
{{post.createdBy.firstName}{{post.createdBy.lastName}
{{post.createdBy.profession}
{{post.title}
{{post.description}}
5名追随者
4评论
61视图
+5名同事正在关注这一点
您可以添加视图代码吗?我猜ng应该是:ng重复:)不。。在angular2中,他们更改了它的语法https://angular.io/docs/ts/latest/api/common/NgFor-directive.html
哦,对不起,我没注意到是angular2。你能分享你的视图代码吗?你能发布你模板的主体吗?是的,我肯定我已经更新了问题