chatroom.service.ts:角度+ Firebase:リストのプロパティでオブジェクトを保存/取得する方法は?
...
export class Message {
author: string;
body: string;
}
export class Chatroom {
title: string;
messages: Message[]; // <-- seems to be the problem
}
@Injectable()
export class ChatroomService {
...
getChatroom = (chatroomId: string): FirebaseObjectObservable<Chatroom> =>
this.db.object('/chatrooms/' + chatroomId);
...
chatroom.component.ts:
...
export class ChatroomComponent implements OnInit {
chatroom: Chatroom;
private sub: any;
ngOnInit() {
this.sub = this.route.params
.subscribe(params => {
this.sub = this.chatroomService.getChatroom(params['chatroomId'])
.subscribe(chatroom => this.chatroom = chatroom);
});
}
...
chatroom.component.html
<div *ngIf="chatroom">
<p *ngFor="let message of chatroom.messages">{{message.author}}: {{message.body}}</p>
</div>
エラー:
Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
問題はそれですChatroomオブジェクトの "message"プロパティはFirebaseによってオブジェクトとして扱われますが、これはngFor-iterableリストとして扱われます。どのようにこの作品を作るための任意の提案?
EDIT:リストのようなもので
{
"chatrooms" : {
"chatroom_342768235" : {
"title" : "a chatroom",
"messages" : {
"message_3252253" : {
"author" : "Joe",
"body" : "test message"
},
"message_2653837" : {
"author" : "Kim",
"body" : "another message"
}
}
},
"chatroom_426482763" : {
"title" : "another chatroom",
"messages" : {
"message_1243525" : {
"author" : "Tom",
"body" : "blah blah"
}
}
}
}
}
チャットルーム内には何がありますか? – Sajeetharan
anglefire2(https://github.com/angular/angularfire2)を使用していますか? – happyZZR1400