首页 文章

尝试在nativescript-angular移动应用程序中使用ngrx-store-localstorage导致'localStorage is not defined'

提问于
浏览
0

ReferenceError:localStorage未定义文件:“finle:///data/data/org.nativescript/dist/index.js.line 104,column:40 StackTrace:Frame:function:'exports.localStorageSync',file:' file:///data/data/org.nativescript.MyApp/files/app/tns_modules/ngrx-store-localstorage/dist/index.js',line:1010,column:41 Frame:finction:“,file:'文件:///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

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

    tns plugin add nativescript-localstorage
    

    在初始化ngrx之前,在 app.module.ts 的顶部:

    import 'nativescript-localstorage';
    

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

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

  • 1

    你必须做三个步骤

    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 {
     ......
    }
    

相关问题