在我的 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!
有什么建议吗?
答案 0 :(得分:1)
if(resultCode == 0){
//Intent intent = getIntent();
String name2 = data.getStringExtra("namev");
String email2 = data.getStringExtra("emailv");
String birthday2 = data.getStringExtra("birthdayv");
Log.d("AAA",">>>:"+name2);
Contact person = new Contact(name2,email2,birthday2);
allContact.add(person);
}}
是一个Observable(FirebaseListObservable)。您需要订阅它才能获取数据。
您可以使用:
this._angularFire.database.list('songs/'+key)