【发布时间】:2017-04-18 00:49:45
【问题描述】:
在我的服务文件中:
postDetail: FirebaseObjectObservable<any>;
constructor( private af: AngularFire ) { }
public getBanquetDetail(id){
this.postDetail = this.af.database.object('/Posts/'+id) as FirebaseObjectObservable<Post>;
return this.postDetail;
}
在我的 component.ts 文件中
export class PostDetailComponent implements OnInit {
id: any;
test: any;
constructor(private banquetService: PostService, private router: Router, private route: ActivatedRoute) { }
ngOnInit() {
// Get the id
this.id = this.route.snapshot.params['id'];
this.banquetService.getBanquetDetail(this.id).subscribe(response => {
console.log(response)
this.test = response
})
}
}
我在控制台中获取了一个对象,但无法将值呈现为
<h2>{{test.title}}</h2>
我收到错误:
TypeError: 无法读取未定义的属性“标题”
有人请帮帮我吗?我在哪里穿?
【问题讨论】:
标签: angular firebase firebase-realtime-database angularfire2