本文整理匯總了TypeScript中angular-2-local-storage.LocalStorageService.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript LocalStorageService.get方法的具體用法?TypeScript LocalStorageService.get怎麽用?TypeScript LocalStorageService.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular-2-local-storage.LocalStorageService
的用法示例。
在下文中一共展示了LocalStorageService.get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: canActivate
canActivate(): Observable<boolean> | boolean {
//var tempRoute = state.url;
if (this.localStorageService.get("accessToken")) {
var user_name = this.localStorageService.get<string>("userEmail");
var access_token = this.localStorageService.get<string>("accessToken");
var refresh_token = this.localStorageService.get<string>("refreshToken");
//Check Validate Token
if (this.AuthService.checkValidateToken(access_token)) {
//Exist Token
//Check Time Token
var datetime = (Date.now() / 1000);
var expires_time = this.localStorageService.get<number>("expiresTime");
var remain_time = expires_time - datetime;
if (remain_time > -1) {
//Refresh Token
if (remain_time < 600) {
//api to refresh Token
return this.AuthService.refreshToken(user_name, access_token, refresh_token).map(response => {
if (response) {
this.localStorageService.set("accessToken", response.access_token);
this.localStorageService.set("refreshToken", response.refresh_token);
this.localStorageService.set("expiresTime", (Date.now() / 1000) + response.expires_in);
console.log("refresh token");
this.AuthService.checkRoleForRedirect(/*tempRoute*/);
return true;
} else {
response => {
console.log("Try to Login again");
}
}
})
} else {
//console.log("exist token");
//check user data
this.AuthService.checkRoleForRedirect(/*tempRoute*/);
return true;
}
} else {
console.log("expire token");
this.navCtrl.push(LoginComponent);
}
} else {
//Wrong Token
console.log("wrong token");
this.navCtrl.push(LoginComponent);
}
} else {
console.log("not have token");
this.navCtrl.push(LoginComponent);
}
}
示例2: getCurrentConnectionProfile
getCurrentConnectionProfile(): string {
let result = this.localStorageService.get<string>('currentConnectionProfile');
if (result === null) {
result = '$default';
}
return result;
}
示例3: intercept
intercept(req: HttpRequest<any>, next: HttpHandler) {
const authToken = this._localStorageService.get<string>(AuthConstants.getAuthTokenKey());
const authReq = req.clone({
setHeaders: {
'Content-Type': 'application/json; charset=utf-8',
'Accept': 'application/json',
'Authorization': authToken,
},
});
return next.handle(authReq);
}
示例4: constructor
constructor(private localStorageService: LocalStorageService) {
this.isLogged = !!this.localStorageService.get("userToken");
}
示例5: checkRoleForRedirect
checkRoleForRedirect(/*tempRoute: string*/) {
let Users = this.localStorageService.get<UserModel>("User");
console.log('User =>> ', Users);
}
示例6: getItem
getItem(key) {
return this.storage.get(key);
}