本文整理汇总了TypeScript中angular2/angular2.Http类的典型用法代码示例。如果您正苦于以下问题:TypeScript Http类的具体用法?TypeScript Http怎么用?TypeScript Http使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Http类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(http: Http) {
this.data = {};
http.get('foo.json')
.map(res => res.json())
.subscribe(data => {
this.data = data;
console.log(this.data);
})
}
示例2: signup
signup(event, username, password) {
event.preventDefault();
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
this.http.post('http://localhost:3001/users',
JSON.stringify({
username, password
}),
{
headers: headers
}
)
.toRx()
.map(status)
.map(json)
.subscribe(
response => {
localStorage.setItem('jwt', response.id_token);
this.router.navigate('/home');
},
error => {
alert(error.message);
console.log(error.message);
}
);
}
示例3: Headers
_callApi(type, url) {
this.response = null;
this.api = type;
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'bearer ' + this.jwt);
this.http.get(url, {headers: headers})
.toRx()
.map(status)
.map(text)
.subscribe(
response => {
this.response = response;
},
error => {
this.response = error.message;
}
)
}
示例4: retrieveData
retrieveData() {
this.http.get('http://www.dynamopackages.com/packages/');
//.map(res => res.json()).subscribe(data => { this.data = data.content;})
}