2017-05-25 6 views
0

localforageライブラリをAngular 4プロジェクトに使用しようとしています。localforageを注入可能なサービスにインポートできません

私はすでにやった:

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

何だろう:これは私の注射用サービス

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

constructor(){} 

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

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

この戻り息子npm startある

--save localforageを

NPMをインストール間違っている? 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"); 
関連する問題