我想有一个通用的HTTP GET服务,我这样做是使用下面的代码:Angular2打字稿承诺
public get(module: String): Promise<any> {
return this.http.get(module)
.toPromise()
.then(response => response.json().data as Any[])
.catch(this.handleError);}
的问题是,现在我想知道当http.get完成发射命令,我不知道该怎么做。
如果我补充一点到。然后一步这是行不通的
.then(response => response.json().data as Any[] && alert("HI"))
如果我在其他then
后添加.then
,它触发被满足的HTTP请求之前。
我该如何实现它?
使用dfsq代码我能够发出警报(“HI”),但响应未定义。这是我使用它的方式:
this.dataService.get(“myurl”)。then(response => console.log(response));
我得到了一个未定义
“如果我在其他时间之后添加一个.then,它会在满足http请求之前触发。”你能显示这个代码吗?这不是如何承诺链接工程 –
@suraj我想它是'然后(警报(“嗨”))'。 – dfsq