前端之家收集整理的这篇文章主要介绍了
angular2 http 请求,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
export class MsgTestComponent implements OnInit {
data: any;
constructor(private http: Http) {}
ngOnInit() {
}
postTest() {
//参数传递,放到body里
var reqJson = {name: "1234",upstream_url: "http://192.168.1.45:33890",request_host: "1234.com"};
this.http.post("http://192.168.1.46:8001/apis",reqJson)
.map(resp => {
console.log(resp);
this.data = resp.json();
})
.subscribe();
}
getTest() {
//get方式不用传参
this.http.get("http://192.168.1.46:8001/apis")
.map(res => {
console.log(res);
this.data = res.json()
})
.subscribe();
}
}