本文整理匯總了TypeScript中@ionic-native/native-storage.NativeStorage.getItem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript NativeStorage.getItem方法的具體用法?TypeScript NativeStorage.getItem怎麽用?TypeScript NativeStorage.getItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ionic-native/native-storage.NativeStorage
的用法示例。
在下文中一共展示了NativeStorage.getItem方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
this.serverProvider.post(this.storageProvider.serverAddress+"/preventMultiLogin",body).then((res:any)=>{
console.log("res:"+JSON.stringify(res));
if(res.result=="success"){
// move into TabPage
if(res.userInfo.hasOwnProperty("shopList")){
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
//save this.storageProvider.id
this.storageProvider.userInfoSetFromServer(res.userInfo);
//save id information into storage
let id=this.navParams.get("id");
if(id!=undefined){
var encrypted:string=this.storageProvider.encryptValue('id',id);
this.nativeStorage.setItem('id',encodeURI(encrypted));
this.storageProvider.id=id;
}else{
//read id info and then save it into storageProvider
this.nativeStorage.getItem("id").then((value:string)=>{
this.storageProvider.id=this.storageProvider.decryptValue("id",decodeURI(value));
});
}
console.log("move into TbasPage");
this.app.getRootNav().setRoot(TabsPage);
}else{
console.log("move into LoginPage");
// move into loginPage
this.storageProvider.reset();
this.app.getRootNav().setRoot(LoginPage);
}
});
示例2: loginUser
loginUser(){
console.log("Username:" + this.loginForm.value.username);
console.log("Password:" + this.loginForm.value.password);
this.nativeStorage.getItem(this.loginForm.value.username).then(
user => {
console.log("logged in user: "+JSON.stringify(user));
if(this.loginForm.value.password===user.password){
console.log("storing in localstorage: "+user.username)
this.storage.set("username",user.username).then((username)=>{
console.log("stored in local: "+username);
this.storage.set("loggedIn",true).then((loggedIn)=>{
console.log("loggeado "+loggedIn);
});
this.navCtrl.setRoot(ProfilePage);
});
}else{
let alert =this.alertCtrl.create({
title:"Incorrect password",
buttons:['OK']
});
alert.present();
}
}, error => console.error(error)
);
}
示例3:
this.storage.get("username").then((username)=>{
let index= this.favorites.findIndex((favorite)=>favorite.id==id);
this.favorites.splice(index,1);
this.nativeStorage.getItem(username).then((user)=>{
user.favorites=this.favorites;
this.nativeStorage.setItem(user.username,user).then(()=>{
console.log("deleted favorite")
},error=>{console.error("error en set item")})
})
})
示例4: Promise
return new Promise((resolve,reject)=>{
console.log("[loginAgain] id:"+this.storageProvider.id);
if(this.storageProvider.id=="facebook"){
this.fbProvider.login().then((res:any)=>{
if(res.result=="success"){
if(parseFloat(res.version)>parseFloat(this.storageProvider.version)){
console.log("post invalid version");
this.storageProvider.tabMessageEmitter.emit("invalidVersion");
}
resolve();
}else
reject("HttpFailure");
},login_err =>{
reject("NetworkFailure");
});
}else if(this.storageProvider.id=="kakao"){ //kakao login
console.log("kakao login is not implemented yet");
this.kakaoProvider.login().then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
if(parseFloat(res.version)>parseFloat(this.storageProvider.version)){
console.log("post invalid version");
this.storageProvider.tabMessageEmitter.emit("invalidVersion");
}
resolve();
//save shoplist
resolve();
}else
reject("HttpFailure");
},login_err =>{
reject("NetworkFailure");
});
}else{ // email login
this.nativeStorage.getItem("password").then((value:string)=>{
var password=this.storageProvider.decryptValue("password",decodeURI(value));
this.emailProvider.EmailServerLogin(this.storageProvider.id,password).then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
if(parseFloat(res.version)>parseFloat(this.storageProvider.version)){
console.log("post invalid version");
this.storageProvider.tabMessageEmitter.emit("invalidVersion");
}
resolve();
}else
reject("HttpFailure");
},login_err =>{
reject("NetworkFailure");
});
});
}
});
示例5: tryLogin
tryLogin(event){
if(this.storageProvider.id==undefined){
this.nativeStorage.getItem("id").then((value:string)=>{
console.log("value:"+value);
if(value==null){
console.log("id doesn't exist");
this.app.getRootNav().setRoot(LoginPage);
return;
}else{
var id=this.storageProvider.decryptValue("id",decodeURI(value));
console.log("id:"+id);
this.loginWithExistingId();
}
});
}else{
this.loginWithExistingId();
}
}
示例6: loginWithExistingId
loginWithExistingId(){
var id=this.storageProvider.id;
if(id=="facebook"){
this.fbProvider.login().then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
//save shoplist
console.log("res.email:"+res.email +"res.name:"+res.name);
if(res.userInfo.hasOwnProperty("shopList")){
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
this.storageProvider.emailLogin=false;
this.storageProvider.userInfoSetFromServer(res.userInfo);
console.log("shoplist...:"+JSON.stringify(this.storageProvider.shoplist));
this.app.getRootNav().setRoot(TabsPage);
}else if(res.result=='failure' && res.result=='invalidId'){
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
}else if(res.result=='failure'&& res.error=='multiLogin'){
// How to show user a message here? move into error page?
// Is it possible to show alert here?
this.app.getRootNav().setRoot(MultiloginPage,{id:"facebook"});
}else{
console.log("invalid result comes from server-"+JSON.stringify(res));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
this.app.getRootNav().setRoot(ErrorPage);
}
},login_err =>{
console.log("move into ErrorPage-"+JSON.stringify(login_err));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
});
}else if(id=="kakao"){ //kakao login
//console.log("kakao login is not implemented yet");
// read kakao id and try server login
this.kakaoProvider.login().then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
//save shoplist
if(res.userInfo.hasOwnProperty("shopList")){
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
this.storageProvider.emailLogin=false;
this.storageProvider.userInfoSetFromServer(res.userInfo);
this.app.getRootNav().setRoot(TabsPage);
}else if(res.result=='failure' && res.result=='invalidId'){
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
}else if(res.result=='failure'&& res.error=='multiLogin'){
// How to show user a message here? move into error page?
// Is it possible to show alert here?
this.app.getRootNav().setRoot(MultiloginPage,{id:"kakao"});
}else{
console.log("invalid result comes from server-"+JSON.stringify(res));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
}
},login_err =>{
console.log(JSON.stringify(login_err));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
});
}else{ // email login
this.nativeStorage.getItem("password").then((value:string)=>{
var password=this.storageProvider.decryptValue("password",decodeURI(value));
this.emailProvider.EmailServerLogin(id,password).then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
if(res.userInfo.hasOwnProperty("shopList")){
//save shoplist
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
this.storageProvider.emailLogin=true;
this.storageProvider.userInfoSetFromServer(res.userInfo);
this.app.getRootNav().setRoot(TabsPage);
}else if(res.result=='failure'&& res.error=='multiLogin'){
// How to show user a message here? move into error page?
// Is it possible to show alert here?
this.app.getRootNav().setRoot(MultiloginPage,{id:id});
}else{
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
}
},login_err =>{
console.log(JSON.stringify(login_err));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
});
},(error)=>{
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
});
}
}
示例7:
tokenGetter: (() => nativeStorage.getItem('id_token'))