gpt4 book ai didi

angular - 将外部库与 Angular cli 一起使用

转载 作者:搜寻专家 更新时间:2023-10-30 21:17:53 24 4
gpt4 key购买 nike

我已经安装了一个第三方模块 jsPDF用我的 Angular 应用程序。该模块运行良好,但我的控制台出现错误:

找不到模块“../../../node_modules/jspdf/dist/jspdf.min.js”

我做了什么:

  1. 通过 npm 安装模块:

npm install MrRio/jsPDF --save

  1. 在我的组件中导入模块:

从 '../../../node_modules/jspdf/dist/jspdf.min.js' 导入 * 作为 jsPDF;

  1. 然后在我的组件中简单地使用这个模块。

这里缺少什么吗?

最佳答案

查看此处的说明:github.com/angular/angular-cli#3rd-party-library-installatio‌​n .

如果 jsPDF(或任何其他库)需要在全局范围内,您需要将 JS 文件添加到 apps[0].scripts在你的angular-cli.json文件,然后 WebPack 将其打包,就好像它是用 <script> 加载的一样标签。如果这样做,可以通过添加 declare var jsPDF: any; 来实现。在你的src/typings.d.ts或组件。

但是,看起来有 jsPDF 的类型 npmjs.com/package/@types/jspdf所以你可以在运行后包含它 npm install --save-dev @types/jspdf ;你应该能够 import { jsPDF } from 'jspdf';在你的组件中。

关于angular - 将外部库与 Angular cli 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com