我已经在我的角度应用程序中安装了一个第三方模块 jsPDF .该模块可以正常工作,但在控制台中出现错误:
I have installed one 3rd party module jsPDF with my angular app. The module works perfectly but I get an error in my console:
Cannot find module '../../../node_modules/jspdf/dist/jspdf.min.js'.
我做什么:
npm install MrRio/jsPDF --save
import * as jsPDF from '../../../node_modules/jspdf/dist/jspdf.min.js';
这里缺少什么吗?
推荐答案在此处查看说明: github/angular/angular-cli#3rd-party-library-installation .
如果jsPDF(或任何其他库)需要在全局范围内,则需要将JS文件添加到angular-cli.json文件中的apps[0].scripts中,然后WebPack将其打包,就像它是用<script>标记.如果这样做,可以通过在src/typings.d.ts或组件中添加declare var jsPDF: any;来实现.
If jsPDF (or any other library) needs to be in the global scope, you will need to add the JS file to apps[0].scripts in your angular-cli.json file, which WebPack then bundles as if it were loaded with a <script> tag. If you do that, you can get at it by adding declare var jsPDF: any; in your src/typings.d.ts or component.
但是,看起来好像有jsPDF的类型 npmjs/package/@types/jspdf ,因此您可以在运行npm install --save-dev @types/jspdf之后将其包括在内;您应该可以在组件中import { jsPDF } from 'jspdf';.
However, it looks like there are typings for jsPDF npmjs/package/@types/jspdf so you can include it after running npm install --save-dev @types/jspdf; you should be able to import { jsPDF } from 'jspdf'; in your component.
更多推荐
将外部库与angular cli一起使用
发布评论