我在我的应用程序中使用吼包。我安装使用npm install --save @types/howler
的分型,在我的index.html我已经包含下面的脚本标签
<script src="./node_modules/howler/dist/howler.min.js"></script>
但它仍然显示错误error TS2304: Cannot find name 'Howl'
当我尝试使用NG服务命令为我的应用程序。
安装号哭和打字稿定义:
npm install howler --save
npm install @types/howler --save
你并不需要把它导入到你的index.html文件,只需要导入howler
直接在您的组件类:
import { Howl } from 'howler';
有时候,如果你有没有modules导入库,你只需要与申报关键字declare the variable。
例如,离开你的脚本在您的index.html:
<script src="./node_modules/howler/dist/howler.min.js"></script>
但随后在组件(如果你确信这个脚本将被载入),你可以声明嚎叫:
import { Component } from '@angular/core';
declare var Howl; <-- declare above @Component
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 5';
}
注意:您通常看到这个使用jQuery:declare var $;