简体   繁体   English

如何在 Angular 中集成 WinBox JS?

[英]How to integrate WinBox JS in Angular?

I am playing with a javascript library called WinBoxJS.我正在玩一个名为 WinBoxJS 的 javascript 库。 I know how to use this with plain JS.我知道如何将它与普通 JS 一起使用。 I am trying to use it in my Angular project.我正在尝试在我的 Angular 项目中使用它。 How can I do that?我怎样才能做到这一点?

https://www.npmjs.com/package/winbox

I installed the winbox using npm.我使用npm安装了winbox。 I also included the styles and scripts in the angular.json.我还在 angular.json 中包含了 styles 和脚本。 I acn make it work if I use the JS and CSS files and add some script in index.html.如果我使用 JS 和 CSS 文件并在 index.html 中添加一些脚本,我会使其工作。 But, I want it to Angular way.但是,我希望它以 Angular 的方式。 Any idea?任何想法?

DISCLAIMER: The code below works for the current version of winbox ie winbox@0.1.92免责声明:以下代码适用于当前版本的winbox ,即winbox@0.1.92

You can use it in Angular by following the steps below:您可以按照以下步骤在 Angular 中使用它:

  1. Install winbox:安装winbox:

    npm i winbox@0.1.92

  2. Add winbox CSS to your styles.css / styles.scss :将 winbox CSS 添加到您的styles.css / styles.scss

    @import '~winbox/dist/css/winbox.min.css';

  3. Add the winbox bundle to your angular.json scripts at path - ( projects.projectName.architect.build.options.scripts ):winbox包添加到您的angular.json脚本路径 - ( projects.projectName.architect.build.options.scripts ):

     "scripts": [ "node_modules/winbox/dist/winbox.bundle.js" ]
  4. Add a declaration for WinBox to your Component.将 WinBox 的声明添加到您的组件。 The line below declares WinBox in app.component.ts :下面的WinBox中声明了app.component.ts

    declare const WinBox: any;

  5. Use WinBox as per their Documentation here .根据此处的文档使用 WinBox。

Here's a Working Sample StackBlitz for your ref.这是您参考的工作示例 StackBlitz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM