本文整理汇总了TypeScript中angular2-jwt.AuthHttp类的典型用法代码示例。如果您正苦于以下问题:TypeScript AuthHttp类的具体用法?TypeScript AuthHttp怎么用?TypeScript AuthHttp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthHttp类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _callApi
_callApi(type, url) {
this.response = null;
if (type === 'Anonymous') {
// For non-protected routes, just use Http
this.http.get(url)
.subscribe(
response => this.response = response.text(),
error => this.response = error.text()
);
}
if (type === 'Secured') {
// For protected routes, use AuthHttp
this.authHttp.get(url)
.subscribe(
response => this.response = response.text(),
error => this.response = error.text()
);
}
}
示例2: Error
addEvent(event: any) {
let body = JSON.stringify(event);
let headers = xhrHeaders();
let options = new RequestOptions({ headers });
return this.authHttp.post(environment.backendURL + '/planner/add', body, options)
.map(res => {
let data = res.json();
// Check if server-side error
if (data.error) {
throw new Error(data.error);
}
return data.events;
})
.catch(handleError);
}
示例3: Error
post(moduleId: string, text: string) {
let body = JSON.stringify({ moduleId, text });
let headers = xhrHeaders();
let options = new RequestOptions({ headers });
return this.authHttp.post(environment.backendURL + '/stickynotes/post', body, options)
.map(res => {
let data = res.json();
// Check if server-side error
if (data.error) {
throw new Error(data.error);
}
return data.success;
})
.catch(handleError);
}
示例4: Error
upsert(modules: Module[]): Observable<Module[]> {
let body = JSON.stringify({ modules });
let headers = xhrHeaders();
let options = new RequestOptions({ headers });
return this.authHttp.post(environment.backendURL + '/modules/upsert', body, options)
.map(res => {
let data = res.json();
// Check if server-side error
if (data.error) {
throw new Error(data.error);
}
return data.modules;
})
.catch(handleError);
}
示例5: Error
deleteClass(id: string) {
let body = JSON.stringify({ id });
let headers = xhrHeaders();
let options = new RequestOptions({ headers });
return this.authHttp.post(environment.backendURL + '/classes/delete', body, options)
.map(res => {
let data = res.json();
// Check if server-side error
if (data.error) {
throw new Error(data.error);
}
return;
})
.catch(handleError);
}
示例6: Error
getScores() {
let body = JSON.stringify({});
let headers = xhrHeaders();
let options = new RequestOptions({ headers });
return this.authHttp.post(environment.backendURL + '/user/get-info', body, options)
.map( res => {
let data = res.json();
// Check if server-side error
if (data.error) {
throw new Error(data.error);
}
return data.user;
})
.catch(handleError);
}
示例7: Error
getClasses() {
let body = JSON.stringify({});
let headers = xhrHeaders();
let options = new RequestOptions({ headers });
return this.authHttp.post(environment.backendURL + '/canvas/get-classes', body, options)
.map(res => {
let data = res.json();
// Check if server-side error
if (data.error) {
throw new Error(data.error);
}
return {
hasURL: data.hasURL,
classes: data.classes
};
})
.catch(handleError);
}
示例8: Promise
return new Promise((resolve, reject) => {
if (!this.getToken()) {
this.http.post(
API.URL + 'oauth/access_token',
API.MERGE_PARAMS(credentials)
).subscribe(
data => {
let response = data.json();
localStorage.setItem('access_token', response['access_token']);
resolve(response);
},
err => {
console.log(err);
reject(err);
},
() => console.log('finish request')
);
} else {
resolve();
}
});