本文介绍了如何使用Angular 2在http服务中发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个URL数组,我需要将它们作为http服务url路径发送,并根据响应类型生成结果.示例数组如下.
I have an array of urls which I need to send as the http service url path and generate the result based on the response type. the example array is as below.
this.urlArray = ["www.test.com","www.test2.com"];
我遍历数组并生成div,并将URL作为参数发送到http服务,并根据请求类型(例如超时"),成功和错误将更改div的颜色.谁能告诉我该怎么做.
I iterate over the array and generate div and will send the url to http service as parameter and based on the request type like "time-out", success and error will change the div color. Can anybody please tell how should I proceed.
推荐答案
来自 https://angular.io/docs/ts/latest/guide/server-communication.html
addHero (name: string): Observable<Hero> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.heroesUrl, /*{ name }*/ this.urlArray, options)
.map(this.extractData)
.catch(this.handleError);
}
这篇关于如何使用Angular 2在http服务中发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!