Can't resolve all options for store: (?) - Angular JWT Application Module
I am trying to set up Angular2-Jwt for Ionic 2. Before updating Ionic, the following code worked. This is no longer the case. I know there was a change in Ionic Storage wihch causing the problem, but I don't understand how I can convert the following code:
import { BrowserModule } from '@angular/platform-browser';
import { Http } from '@angular/http';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { AuthHttp, AuthConfig } from 'angular2-jwt';
import { ElasticModule } from 'angular2-elastic';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { NumberBoard } from '../components/number-board/number-board';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { CloudSettings, CloudModule } from '@ionic/cloud-angular';
import { IonicStorageModule, Storage } from '@ionic/storage';
let storage: Storage = new Storage();
export function getAuthHttp(http) {
return new AuthHttp(new AuthConfig({
headerName: 'token',
noTokenScheme: true,
globalHeaders: [{'Accept': 'application/json'}],
tokenGetter: (() => storage.get('token'))
}), http);
};
const cloudSettings: CloudSettings = {
'core': {
'app_id': 'c3890396'
}
};
@NgModule({
declarations: [
MyApp,
HomePage,
NumberBoard
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
CloudModule.forRoot(cloudSettings),
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
{provide: AuthHttp, useFactory: getAuthHttp, deps: [Http]},
]
})
export class AppModule {}
Package.json:
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/compiler-cli": "4.0.0",
"@angular/core": "4.0.0",
"@angular/forms": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-browser-dynamic": "4.0.0",
"@ionic-native/core": "3.4.2",
"@ionic-native/crop": "^3.4.4",
"@ionic-native/image-picker": "^3.4.4",
"@ionic-native/splash-screen": "3.4.2",
"@ionic-native/status-bar": "3.4.2",
"@ionic/cloud-angular": "^0.11.0",
"@ionic/storage": "2.0.1",
"angular2-elastic": "^0.13.0",
"angular2-jwt": "^0.2.0",
"ionic-angular": "3.0.0",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.4.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@ionic/app-scripts": "1.3.0",
"typescript": "~2.2.1"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "Rediyal-Business: An Ionic project"
}
+3
source to share
1 answer
Looks like:
let storage: Storage = new Storage();
does not work in version 2.0.0 onwards. Check the ion storage code . Its constructor takes a parameter.
constructor(config: StorageConfig)
You can use it by typing in the constructor like the provider though.
constructor(private storage: Storage)
A set of attachments for dependencies is here .
{ provide: Storage, useFactory: provideStorage, deps: [StorageConfigToken]},
Also try
let storage: Storage = new Storage(null);
+2
source to share