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

TypeError: Cannot read property 'get' of undefined - STORAGE

$
0
0

@DianLabuschagne wrote:

import { Injectable } from '@angular/core';
import { SessionProvider } from '../sessionprovider';
import { SqliteProvider } from '../sqlite/sqlite'
import {Storage} from '@ionic/storage'

/*
  Generated class for the ConnectioncheckproviderProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class ConnectioncheckproviderProvider {
  state:any;
  // static get parameters() {
  //   return [[HttpClient], [Storage]];
  // }
  
  constructor(private storage: Storage, public http: HttpClient,public session:SessionProvider,public sqlite:SqliteProvider) {
    window.addEventListener('online', this.changestate);
    window.addEventListener('offline', this.changestate);
      storage.get('age').then((val) => {
        console.log('from asyncTest --> Your age is', val);
      });

         setInterval(this.test,5000)

  }
  

  changestate(){
    this.storage.get('age').then((val) => {
      console.log('from asyncTest --> Your age is', val);
    });
    this.state=navigator.onLine ? 'online' : 'offline'
  }```

Please help: Why do I get undefined error - like in the title - when changestate is called, but in the constructor it works fine (get null for the value because there is nothing in storage)?

Posts: 1

Participants: 1

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>