无法将localforage导入Injectable服务

时间:2017-05-25 09:55:03

标签: angular typescript localforage

我试图将localforage库用于我的Angular 4项目。

我已经完成了:

npm install localforage --save

这是我的可注射服务

import {Injectable} from "@angular/core";
import {localForage} from "localforage";

constructor(){}

    setAccessToken(aToken:string){
        localForage.setItem('accessToken', aToken)
    }

    getAccessToken(){
        return localForage.getItem('accessToken')
    }

这个回归的儿子npm start

error TS2305: Module '"localforage"' has no exported member 'localForage'.

会出错的是什么?

2 个答案:

答案 0 :(得分:0)

您的导入应如下所示:

import * as localForage from  "localforage";

答案 1 :(得分:0)

来自localForage github readme

  

打字稿

     

如果tsconfig.json中的allowSyntheticDefaultImports编译器选项设置为true(TypeScript v1.8 +支持),则应使用:

import localForage from "localforage";
     

否则您应该使用以下之一:

import * as localForage from "localforage";
// or, in case that the typescript version that you are using
// doesn't support ES6 style imports for UMD modules like localForage
import localForage = require("localforage");