尝试在nativescript-angular移动应用程序中使用ngrx-store-localstorage导致'localStorage未定义'

时间:2017-05-21 21:33:15

标签: angular nativescript ngrx angular2-nativescript ngrx-store

  

ReferenceError:未定义localStorage

     

文件:“finle:///data/data/org.nativescript/dist/index.js。第104行,   专栏:40

     

StackTrace:框架:   功能: 'exports.localStorageSync',文件:“文件:///data/data/org.nativescript.MyApp/files/app/tns_modules/ngrx-store-localstorage/dist/index.js',line:104,柱:41   帧:   finction:”,文件:“文件:///data/data/org.nativescript.MyApp/files/app/core/store/index.js',line:19,柱:69

是否必须使用https://www.npmjs.com/package/nativescript-localstorage 或者我们可以使用https://github.com/natural-apptitude/ngrx-store-ionic-storage 或者ngrx-store-localstorage

2 个答案:

答案 0 :(得分:1)

NativeScript没有LocalStorage。你必须安装一个垫片。

List[str]

然后在初始化ngrx之前位于tns plugin add nativescript-localstorage 的顶部:

app.module.ts

这应该允许ngrx-store-localstorage工作。

阅读以下文档: https://github.com/NathanaelA/nativescript-localstorage

答案 1 :(得分:0)

您必须执行三个步骤

1安装插件

tns plugin add nativescript-localstorage

2将其导入app.module.ts

import 'nativescript-localstorage';

3在相应组件中使用

import { Component, OnInit } from "@angular/core";
import { DataService, IDataItem } from "../core/data.service";
require( "nativescript-localstorage" );
@Component({
....
})

 export class HomeComponent implements OnInit {
 ......
}
相关问题