我正在尝试导入angular 6中的tone.js。正如tone.js安装文档中所述,我安装了tone.js。
npm - npm install tone
我试图在app.module.ts中导入Tone
import { ToneJs } from 'tone';
imports: [
ToneJs,
...
]
我有这个例外:
Error: Unexpected value 'undefined' imported by the module 'AppModule'
如何使用angular导入和使用tone.js?
这是我的角度版本
ng -v
Angular CLI: 6.0.1
Node: 8.11.1
OS: darwin x64
Angular: 6.0.1
编辑:
当我尝试将其加载到组件中时
import { Component } from '@angular/core';
import { ToneJs } from 'tone';
@Component({
selector: 'app-player',
templateUrl: './player.component.html',
styleUrls: ['./player.component.css']
})
export class PlayerComponent {
constructor(private toneJs: toneJs) { }
}
我得到:
Error: Can't resolve all parameters for PlayerComponent: (?).
如果您正在使用angular-cli,则可以尝试将ToneJS库作为外部脚本添加到angular.json中
projects
- architect
- build
- scripts
- [ ..., "node_modules/path/to/Tone.js"]
如果您在src / typings.d.ts上没有Types.d.ts文件,请创建此文件并添加以下行 declare var Tone: any;
现在,应该可以在整个应用程序中将ToneJs用作全局变量。因此,您可以像这样使用它:
import { Component } from '@angular/core';
@Component({
selector: 'app-player',
templateUrl: './player.component.html',
styleUrls: ['./player.component.css']
})
export class PlayerComponent {
constructor() {
// const loop = new Tone.Loop((time) => {
// do something
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句