Str*_*der 4 typescript ionic2 ionic3 angular
我是Ionic应用程序开发的新手,我一直在关注相同的教程。
我一直在尝试使用,IonicStorageModule但即使在chrome浏览器移动视图模式下运行应用程序时没有错误,也不会生成本地存储密钥。
在我的app.module.ts,我有
import { IonicStorageModule } from '@ionic/storage';
Run Code Online (Sandbox Code Playgroud)
然后我在imports数组中有以下导入,
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()
],
Run Code Online (Sandbox Code Playgroud)
现在,我创建了一个名为的服务user-settings.service.ts,
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
@Injectable()
export class UserSettings {
constructor(private storage:Storage){}
favoriteTeam(team,tournamentId, tournamentName) {
debugger;
let item = { team: team,tournamentId : tournamentId, tournamentName : tournamentName};
this.storage.set('teamId' , item);
}
unFavoriteTeam(team) {
this.storage.remove(team.id);
}
isFavoriteTeam(team) {
return this.storage.get(team.id).then(value => value ? true : false);
}
}
Run Code Online (Sandbox Code Playgroud)
然后从我的组件,类,当我做..
}else {
this.isFollowing = true;
this.userSettings.favoriteTeam(this.team,this.currentTournamentData.tournament.id,this.currentTournamentData.tournament.name);
}
Run Code Online (Sandbox Code Playgroud)
即使服务被击中,我也看不到local stoargeChrome创建的键application -> storage -> local storage.
我究竟做错了什么 ?
就像您可以在docs中看到的那样:
在网络中运行或作为渐进式Web应用程序运行时,Storage会尝试按该顺序使用IndexedDB,WebSQL和localstorage。
因此,如果您使用的是Chrome,请首先检查数据是否存储在IndexedDB或WebSQL中:
另外请注意,您正在使用teamId密钥设置数据,如下所示:
this.storage.set('teamId' , item);
Run Code Online (Sandbox Code Playgroud)
因此,为了取回该数据,您需要使用相同的密钥:
this.storage.get('teamId').then(value => value ? true : false);
Run Code Online (Sandbox Code Playgroud)
如果要将其从存储设备中删除,也是如此:
this.storage.remove('teamId');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2972 次 |
| 最近记录: |