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