2017-03-05 47 views
0

我正在使用Windows和WebStorm。試圖安裝angular2-localstoragenpm install angular2-localstorage,但出現錯誤。在WebStorm中安裝angular2-localstorage會給出有關「類型安裝」的錯誤

angular2-localstorage項目沒有維護,所以我在這裏發佈。

https://github.com/marcj/angular2-localStorage

錯誤的詳細信息:

npm ERR! Windows_NT 10.0.14393 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "angular2-localstorage" 
npm ERR! node v6.10.0 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 

npm ERR! [email protected] postinstall: `typings install` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script 'typings install'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the angular2-localstorage package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  typings install 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs angular2-localstorage 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls angular2-localstorage 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\Users\***\WebstormProjects\ReusGooRoo2\npm-debug.log 

日誌文件的內容:http://pastebin.com/njG9XMgK

任何幫助表示讚賞。

+0

你已經安裝了全球一分型? – Pengyy

回答

0

由於節點模塊angular2-localstorage未正確維護,因此我建議使用angular-2-local-storage node_module作爲替代方案。

步驟:

  1. 安裝npm install angular-2-local-storage
  2. 確保包在config.js(systemjs或的WebPack)
  3. 導入模塊和服務添加如下

    import { LocalStorageModule,LocalStorageService} from 'angular-2-local-storage'; 
    
  4. 添加模塊以將數組和服務提供給提供程序數組,如

    imports: [ BrowserModule, 
        LocalStorageModule.withConfig({storageType: 'localStorage'}), ], 
    
    providers:[LocalStorageService], 
    
  5. 注入服務作爲依賴,成分如下

    constructor(private localStorageService: LocalStorageService) { 
         this.name = 'Angular-2-Local-Storage-Demo'; 
         this.localStorageService.add('a',this.user); 
         console.log(this.localStorageService.get('a')); 
         this.valuFromLocalStorage= this.localStorageService.get('a') 
    } 
    

LIVE DEMO