Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

At my witts end with Cannot read property 'get' of undefined

$
0
0

@dbinott wrote:

I have tried so many things and I can't get ionic storage to work inside app.module.ts
It's failing on tokenGetter: (() => storage.get('token'))
Hoping someone can help. I am a n00b with Ionic/Angular but not programming.

global packages:

    @ionic/cli-utils : 1.5.0
    Cordova CLI      : 7.0.1
    Ionic CLI        : 3.5.0

local packages:

    @ionic/app-scripts              : 2.0.0
    @ionic/cli-plugin-cordova       : 1.4.1
    @ionic/cli-plugin-ionic-angular : 1.3.2
    Cordova Platforms               : android 6.2.3 browser 4.1.0
    Ionic Framework                 : ionic-angular 3.5.0

System:

    Node       : v8.1.3
    OS         : Windows 10
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
    npm        : 5.0.3

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { S101App } from './app.component';
import { AuthService } from '../providers/auth-service/auth-service';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { LoginPage } from '../pages/login/login';
import { RegisterPage } from '../pages/register/register';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { IonicStorageModule } from '@ionic/storage';
import { AuthHttp, AuthConfig } from 'angular2-jwt';
import { Http, HttpModule } from '@angular/http';
// import { Storage } from '@ionic/storage';
import { Device } from '@ionic-native/device';

import { SchedulePage } from "../pages/schedule/schedule";


export function getAuthHttp(http, storage) {
  return new AuthHttp(new AuthConfig({
    noJwtError: true,
    noTokenScheme: true,
    globalHeaders: [{ 'Content-Type': 'application/json'}],
    tokenGetter: (() => storage.get('token')),  //"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMzNTgsImV4cCI6MTUwMDY2NTA4MSwiZGlkIjoiQTY3NDgwODEtMDg5OC1BMDU0LTlGMzMxODM1RTEzODY0RTgifQ.nMEawzzQtwqmJSxxsA8k0G9FZL9ZSqoLcCwsUEi41U8"),
  }), http);
}

// 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMzNTgsImV4cCI6MTUwMDAyNTExOSwiZGlkIjoiNURGRjdDMTYtRDREOC0xMDEyLTQxNTk4NjVGRDY5RjZBMzEifQ.FWe-jLIG9ryINpHENNwI8ynV-YRtb8tk_M_8VZHJouQ'
@NgModule({
  declarations: [
    S101App,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage,
    LoginPage,
    RegisterPage,
    SchedulePage
  ],
  imports: [
    IonicModule.forRoot(S101App),
    IonicStorageModule.forRoot(),
    BrowserModule,
    HttpModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    S101App,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage,
    LoginPage,
    RegisterPage,
    SchedulePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    Device,
    { provide: ErrorHandler, useClass: IonicErrorHandler },
    AuthService,
    {
      provide: AuthHttp,
      useFactory: getAuthHttp,
      deps: [Http]
    }
  ]
})
export class AppModule { }

Posts: 6

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>