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

前端 未结 4 1984
北荒
北荒 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: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!

提交回复
热议问题