【问题标题】:How to use this jQuery plugin in Angular 4?如何在 Angular 4 中使用这个 jQuery 插件?
【发布时间】:2018-03-24 15:09:10
【问题描述】:

我正在使用 Angular 4(使用 TypeScript 语言)开发一个 Web 应用程序。

我有一个问题,希望很容易解决。

我想在我的应用程序中使用这个 jQuery 插件 (https://harvesthq.github.io/chosen/) 来查看多选。

问题是我无法将它导入我的应用程序(该插件似乎只适用于 html 静态页面!)。

我试图在文件中包含angular-cli.json 对.js文件的依赖,这样:

  "scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/chosen-npm/public/chosen.jquery.min.js",
    "../node_modules/chosen-npm/public/chosen.jquery.js"]

但不幸的是,我无法正确看到多项选择。我不明白如何使用这个插件。

谁能帮助我,也许可以在 Angular 应用程序上尝试一下?

【问题讨论】:

  • 如果它在 jquery 中并且你想在你的 angular 组件中使用它,你可以通过在你的组件中注入 jquery 并使用$ 来调用它们。我认为有很多方法

标签: jquery html angular plugins


【解决方案1】:

这样使用:

.angular-cli.json 在 angular-cli.json 的脚本数组中添加您的 jquery javascript

"scripts": [
  "../node_modules/jquery/dist/jquery.js"
],

app.component.ts

import * as $ from 'jquery';

【讨论】:

  • 他问的是选的,一个 jquery 插件。 jquery 本身并不难。
猜你喜欢
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2018-03-27
  • 2019-12-16
  • 1970-01-01
相关资源
最近更新 更多