Angular2 FileSaver.js - Cannot find module 'file-saver'

前端 未结 4 2011
北荒
北荒 2021-02-19 21:53

I am working on moving an angular 1.x site to a new angular 2.0 site I created the site using angular-cli 1.0.0-beta.15.

I have a button to export some data to a CSV fi

相关标签:
4条回答
  • 2021-02-19 22:41

    Install the Library as follows,

    npm install file-saver --save
    

    This will solve your problem.

    0 讨论(0)
  • 2021-02-19 22:43

    just use this import statment

    import * as fileSaver from 'file-saver';
    
    0 讨论(0)
  • 2021-02-19 22:44

    On angular-cli you should:

    1) install the library to your node_modules:

    npm i -S file-saver
    

    2) add reference of js file on 'scripts' in angular-cli.json file:

    "scripts": ["../node_modules/file-saver/FileSaver.js"]
    

    3) on your typings.d.ts file :

    declare function saveAs();
    

    after that you can use saveAs() everywhere you need example:

    export class MyClass{
      constructor(){
        saveAs(blablabla...)
      }
    }
    

    Good Luck!

    0 讨论(0)
  • 2021-02-19 22:54

    Install the new TypeScript 2 version.. that should work..

    0 讨论(0)
提交回复
热议问题