2017-05-25 74 views
0

我正在尝试将localforage库导入到我的Angular 4项目中。无法将localforage导入到Injectable服务

我已经做了:

NPM安装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'. 

会是什么做错了吗?

回答

0

你的进口应该是这样的:从localForagegithub readme

import * as localForage from "localforage"; 
0

报价。

打字稿

如果你在你的tsconfig.json设置为true allowSyntheticDefaultImports编译器选项(在打字稿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"); 
相关问题