在angular6中使用tone.js [英] using tone.js within angular6

查看:101
本文介绍了在angular6中使用tone.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导入angular 6中的tone.js.如tone.js安装中所述

I'm trying to import tone.js in angular 6. As mention in tone.js installation doc, I installed tone.js.

npm - npm install tone

我尝试在app.module.ts中导入Tone

I tried to import Tone in app.module.ts

import { ToneJs } from 'tone';
imports: [
   ToneJs,
   ...
]

我遇到了这个例外:

Error: Unexpected value 'undefined' imported by the module 'AppModule'

如何导入和使用angular.tone.js?

How I can import and use tone.js with angular?

这是我的棱角分明版本

ng -v
Angular CLI: 6.0.1
Node: 8.11.1
OS: darwin x64
Angular: 6.0.1

当我尝试将其加载到组件中

When I try to load it in a component

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中

If you are using angular-cli, you could try adding the ToneJS library to your angular.json as an external script

projects
- architect
  - build
    - scripts
      - [ ..., "node_modules/path/to/Tone.js"]

如果在src/typings.d.ts上没有Types.d.ts文件,请创建此文件并添加以下行 declare var Tone: any;

if you dont have a typings.d.ts file at src/typings.d.ts, create this file and add this line declare var Tone: any;

现在,应该可以在整个应用程序中将ToneJs用作全局变量.因此,您可以像这样使用它:

Now, ToneJs should be available for you to use throughout the app as a Global variable. So you can use it like this:

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 
        }
    }
}

这篇关于在angular6中使用tone.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆