本文整理匯總了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;})
}