如何在angular 6库中添加外部js文件 [英] How to add external js file in angular 6 library

查看:442
本文介绍了如何在angular 6库中添加外部js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于角度材料的角度库(版本6),为此我需要包括Hammer js库.

I am creating an angular library (version 6) which is based on angular material for which I need to include the hammer js library.

我知道在angular 6中,我们可以在项目的配置下的angular.json中添加外部js库.但这在上述库的情况下不起作用.我试图通过以下方式添加外部库.

I know that in angular 6 we can add the external js library in the angular.json under the project's configuration. But this does not work in case of above library. I tried to add the external library in the following way.

"my-library": {
  "root": "projects/my-library",
  "sourceRoot": "projects/my-library/src",
  "projectType": "library",
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-ng-packagr:build",
      "options": {
        "tsConfig": "projects/my-library/tsconfig.lib.json",
        "project": "projects/my-library/ng-package.json",
        "scripts": [
          "../node_modules/hammerjs/hammer.min.js"
        ]
      }
    }
}

但是我遇到了这个错误.

But I am getting this error.

架构验证失败,出现以下错误: 数据路径"不应具有其他属性(脚本).

Schema validation failed with the following errors: Data path "" should NOT have additional properties(scripts).

请提出在角度库中添加外部js文件的正确方法.

Please suggest what is the correct way to add external js file in the angular library.

推荐答案

关于OP尝试添加Hammer.js的特定示例.只需npm install Hammerjs,然后编辑您的main.ts文件并添加import 'hammerjs',它将在全球范围内可用.

Regarding the OP's specific example trying to add hammer.js. Just npm install hammerjs then edit your main.ts file and add import 'hammerjs' then it will be available globally.

另请参见文章.

这篇关于如何在angular 6库中添加外部js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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