0
做一个POST到火力地堡后,我这个从火力地堡阅读使用JSON在打字稿Angular2
{ "name": "-KBfn7iFNIxSuCL9B-g5" }
- 如何使用打字稿回读从POST请求返回的响应?路由只需要值
-KBfn7iFNIxSuCL9B-g5
。我现有的不完整的代码如下所示:
addHeroGotoHeroDetail() {
let heroId: string;
this._firebaseService.postHero()
.subscribe(response => {
//do something to make the heroId = -KBfn7iFNIxSuCL9B-g5
});
this._router.navigate(['hero-detail', {id: heroId}]);
}
我们的目标是在主页按钮,其中用户可以在其上单击创建在火力地堡一个新的英雄ID,然后在它重定向到新创建英雄详情页面,在那里他可以做更多细节更新。
也做得从火力地堡一个GET后,我此从返回火力地堡
{ "-KBfn-cw7wpfxfGqbAs8": { "created": 1456728705596, "hero": "Hero 1", "...": "..."} }
我应该建立用于通过返回的英雄JSON的接口火力地堡?
如果对于问题2是,界面应该如何显示?
- 如果是对于问题2,要如何使用打字稿解析JSON对象到接口?代码示例将非常感谢。
export interface X {
id: string; //id defined by Firebase e.g. -KBfn-cw7wpfxfGqbAs8
hero: string; //name of the hero e.g. Hero 1
created: number; // The time when the hero was created
}
我们的目标是,以显示英雄的细节给用户,并允许用户如出生日期,性别和等日期的详细信息的英雄添加...,然后用这些变化更新火力地堡。
谢谢Nathan Friend。这看起来有希望。我会尝试这个解决方案。 –
也有一个网站,我喜欢你的解决方案在区域上阅读? –