【问题标题】:Angular 6 usage of external library, scripts array in angular jsonAngular 6 使用外部库,angular json 中的脚本数组
【发布时间】:2019-01-31 04:38:54
【问题描述】:

我有一个简单的问题,我想在 Angular 6 中使用 lame js 库,但我无法实现。

stackbltiz 演示:

https://stackblitz.com/edit/angular-whygjq?file=angular.json

库蹩脚的 js:

https://github.com/zhuker/lamejs

我完成的步骤:

  • npm install lamejs
  • 在脚本中的 angular.json 中,我已将路径粘贴到 node_modules:

“node_modules/lamejs/lame.min.js”

  • 我一直坚持如何在应用程序组件中使用它,在这里的其他主题中,我发现诸如:import * as lame from '????'

如何正确使用它

【问题讨论】:

  • 您是否在组件中尝试过const lamejs = require("lamejs");?而不是import * as lame..
  • 我不确定,但 require 来自 nodejs 应用程序,它不起作用
  • 你也可以用这个。与 nodejs 应用程序相同。当你使用这个时,你不需要将node_module.... js 导入到angular.json
  • 这是向您展示如何使用 require(yourmodule) 的 stackblitz :stackblitz.com/edit/angular-jhun6j

标签: angular


【解决方案1】:

点击左侧的Dependencies面板,添加lamejs

现在在您的Component.ts(或您需要的任何地方)中,只需将其导入即可。

import { Component } from '@angular/core';

import lame from 'lamejs';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  name = 'Angular';

  public tryMe(): void {
    var mp3encoder = new lame.Mp3Encoder(1, 44100, 128); //mono 44.1khz encode to 128kbps

    // etc. See quickstart at https://github.com/zhuker/lamejs
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-16
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 2018-01-11
    相关资源
    最近更新 更多