所以我得到這個當我嘗試從火力無效參數管道 'AsyncPipe'
Invalid argument '{"-KCO4lKzEJPRq0QgkfHO":{"description":"teste","id":1457488598401,"resourceUrl":"tete","title":"test2"}}' for pipe 'AsyncPipe' in [listItems | async in [email protected]:10]
ArcListComponent得到我的數據
import { Component, OnInit } from "angular2/core";
import { FirebaseService } from "../shared/firebase.service";
import { ArcItem } from "./arc-item.model";
@Component({
selector: "arc-list",
template: `
<ul class="arc-list">
<li *ngFor="#item of listItems | async " class="arc-item">
<h3>{{ item.name}}</h3><a [href]="item.resourceUrl" target="_blank" class="btn btn-success pull-right"><span>Go</span></a>
<hr>
<blockquote>{{ item.description }}</blockquote>
<hr>
</li>
</ul>
`
})
export class ArcListComponent implements OnInit {
listItems: string;
constructor(private _firebaseService: FirebaseService) {}
ngOnInit(): any {
this._firebaseService.getResources().subscribe(
resource => this.listItems = JSON.stringify(resource),
error => console.log(error)
);
}
}
firebase_service
import { Injectable } from "angular2/core";
import { Http } from "angular2/http";
import "rxjs/Rx";
@Injectable()
export class FirebaseService {
constructor(private _http: Http) {}
setResource(id: number, title: string, description: string, resourceUrl: string) {
const body = JSON.stringify({ id: id, title: title, description: description, resourceUrl: resourceUrl});
return this._http
.post("https://######.firebaseio.com/resource.json", body)
.map(response => response.json());
}
getResources() {
return this._http
.get("https://######.firebaseio.com/resource.json")
.map(response => response.json());
}
}
我知道我試圖以錯誤的方式顯示我的數據,但我不知道如何解決這個問題。任何幫助讚賞。
您好感謝您的意見,現在我得到這個'無法鰭d [listItems |中有不同的支持對象'[object Object]'異步在ArcListComponent @ 2:10]'請注意,我不得不將我的listItems類型更改爲Observable也。 –
@PetrosKyriakou你的Observable/Promise必須返回一個數組,NgFor不會迭代對象。 –
@EricMartinez有你的例子嗎?我對這類東西很陌生。我的意思是我明白你說的只是不知道該怎麼做 –