本文整理匯總了TypeScript中ng2-cookies.Cookie.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Cookie.set方法的具體用法?TypeScript Cookie.set怎麽用?TypeScript Cookie.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ng2-cookies.Cookie
的用法示例。
在下文中一共展示了Cookie.set方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: login
/**
* 登錄
*/
login(param: LoginParamModel) {
console.log(`用戶 ${param.username} 正在登錄...`);
Cookie.set(CommonConfig.AUTH_USER_NAME, param.username);
const params = HttpUtils.getParams();
params.append('username', param.username);
params.append('password', param.password);
params.append('grant_type', CommonConfig.AUTH_GRANT_TYPE);
params.append('client_id', CommonConfig.AUTH_CLIENT_ID);
const options = HttpUtils.getDefaultRequestOptionsByClient();
options.params = params;
return this.http.post(ApiConfig.AUTHORIZATION_API, param.toJson(), options)
.map(res => res.json())
.subscribe(
data => {
this.saveToken(data);
return true;
},
err => {
CookieUtils.clearBy(CommonConfig.AUTH_USER_NAME);
this.toastyService.error('登錄失敗, 請檢查您的用戶名或密碼');
return false;
});
}
示例2: saveToken
saveToken(token){
var expireDate = new Date().getTime() + (1000 * token.expires_in);
Cookie.set("access_token", token.access_token, expireDate);
console.log('Obtained Access token');
this._router.navigate(['/']);
}
示例3: onLanguageChange
onLanguageChange(language: any) {
this.translate.use(language.locale);
Cookie.set(AppConfig.languageCookieName, language.locale, null, "/");
this.languageService.onLanguageSet(language.locale);
}
示例4: setBy
public static setBy(key: string, value: string) {
const expire = new Date();
const time = Date.now() + ((3600 * 1000) * 1); // 保存1小時cookie
expire.setTime(time);
return Cookie.set(key, value, expire);
}
示例5: saveToken
/**
* 保存授權的token
* @param token token
*/
saveToken(token) {
const expireDate = new Date().getTime() + (1000 * token.expires_in);
Cookie.set(CommonConfig.AUTH_TOKEN, token.access_token, expireDate);
this.router.navigate(['/']);
}