运行时错误无法读取未定义的属性“删除”

时间:2017-04-26 11:24:26

标签: ionic-framework ionic2

我正在使用来自'@ ionic / storage'存储

import {Storage}

运行时错误使用 this.storage.remove('key'); 时无法读取未定义属性'删除' Error

这是我使用的功能代码:this.storage.remove

logout(): void {
            this.storage.remove(this.HAS_LOGGED_IN);
            this.storage.remove('email');
            this.events.publish('user:logout');
          };

2 个答案:

答案 0 :(得分:0)

你必须在构造函数中注入一个count对象:

storage

请注意,您还必须在应用中注册存储模块:

import { Storage } from '@ionic/storage';

constructor(private storage: Storage) {

}

logout(): void {
    this.storage.remove(this.HAS_LOGGED_IN);
    this.storage.remove('email');
    this.events.publish('user:logout');
};

请参阅this documentation

答案 1 :(得分:0)

安装ionic-native包> $ npm install ionic-native --save

并使用它:

import { Storage } from 'ionic-native

//and in component class call it like this

Storage.remove('email');
如果你没有使用包装

,你不需要注入它