【发布时间】:2016-10-10 04:53:09
【问题描述】:
我正在尝试创建一个页面,该页面在单个页面上显示来自 firebase 数据库的单个项目数据。
在我的 app.router.ts 我有:
{ path: 'song/:key', component: SongDetailsComponent }
在我的 song-details.component.ts 我有:
song:any;
constructor(private _route: ActivatedRoute, private _firebaseService: FirebaseService) {}
ngOnInit() {
this._route.params.forEach((params: Params) => {
let id = params['key'];
this.song = this._firebaseService.getSong(id);
});
}
在我的 song-details.componenet.html 我有:
{{ song | json }}
在我的 firebase.service.ts 我有
songsDatabaseRef: any;
constructor(private _angularFire: AngularFire) {
this.songsDatabaseRef = _angularFire.database.list('songs');
}
getSong(key: string) {
return this._angularFire.database.list('songs/'+key);
}
但是当我去指定的路线查看歌曲的详细信息时,我得到一个错误:
error_handler.js:45 EXCEPTION: Uncaught (in promise):
Error: Error in ./SongDetailsComponent class SongDetailsComponent -
inline template:0:0 caused by: Converting circular structure to JSON
添加异步管道后,我得到了要显示的数据,但我无法访问 json 对象的属性。
这是 json 对象:
{ "artist": "Two Friends Big Bootie Mixes", "audio": "https://api.soundcloud.com/tracks/286347553/stream?client_id=90d140308348273b897fab79f44a7c89", "dateCreated": "9/10/2016", "download": "http://smarturl.it/BB10Download", "genres": { "bass": 0, "dubstep": 30, "future": 0, "hipHop": 0, "house": 50, "indie": 0, "pop": 0, "techno": 20 }, "image": "https://i1.sndcdn.com/artworks-000186905340-xin8sf-t500x500.jpg", "title": "2F Big Bootie Mix, Volume 10 - Two Friends", "url": "http://soundcloud.com/twofriendsmixes5/bb10", "$key": "-KTgBcZudwBfhKcm68aa" }
当我尝试获取任何属性时,它说它是未定义。例如:
song title: {{(song | async | json)?.title}}
这将返回 null!
有什么建议吗?
【问题讨论】:
标签: javascript angular typescript firebase firebase-realtime-database