本文整理匯總了TypeScript中ng2-cookies.Cookie.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Cookie.get方法的具體用法?TypeScript Cookie.get怎麽用?TypeScript Cookie.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ng2-cookies.Cookie
的用法示例。
在下文中一共展示了Cookie.get方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: canActivate
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
// 存儲appToken到session
if (!Cookie.get(CommonConfig.AUTH_TOKEN)) {
this.router.navigate(['/user/login']);
return false;
} else {
return true;
}
}
示例2: createHeaders
private createHeaders(contentType: string): Headers {
let headers = new Headers({'Content-Type': contentType});
let token = localStorage.getItem('bhmc_token');
if (!token) {
token = sessionStorage.getItem('bhmc_token');
}
if (token) {
headers.append('Authorization', 'Token ' + token);
}
// This cookie is added to responses by Django
let csrf = Cookie.get('csrftoken');
if (csrf) {
headers.append('X-CSRFToken', csrf);
}
return headers;
}
示例3: getResource
getResource(resourceUrl) : Observable<Foo>{
var headers = new Headers({'Content-type': 'application/x-www-form-urlencoded; charset=utf-8', 'Authorization': 'Bearer '+Cookie.get('access_token')});
var options = new RequestOptions({ headers: headers });
return this._http.get(resourceUrl, options)
.map((res:Response) => res.json())
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
示例4: getUser
public static getUser() {
const data = Cookie.get(CommonConfig.AUTH_USER_INFO);
if (data.length > 0) {
return JSON.parse(data);
}
}
示例5: getUserName
public static getUserName() {
return Cookie.get(CommonConfig.AUTH_USER_NAME);
}
示例6: getBy
public static getBy(key: string) {
return Cookie.get(key);
}
示例7: get
/**
* 獲取授權密鑰
*/
public static get() {
return Cookie.get(CommonConfig.AUTH_TOKEN);
}