Jquery plugins 我正在尝试将Jquery组合树插件集成到Angular 6应用程序中

Jquery plugins 我正在尝试将Jquery组合树插件集成到Angular 6应用程序中,jquery-plugins,angular6,Jquery Plugins,Angular6,我面临此错误。“错误:$(…)。comboTree不是函数” 我已经安装了jquery,@types/jquery。 添加comboTree.js插件和icontainer.js Stackblitz网址: 这是我的密码 app.component.ts 从'@angular/core'导入{Component,OnInit}; 从“jquery”导入美元; @组成部分({ 选择器:“我的应用程序”, templateUrl:“./app.component.html”, 样式URL:['.

我面临此错误。“错误:$(…)。comboTree不是函数”

我已经安装了jquery,@types/jquery。
添加comboTree.js插件和icontainer.js

Stackblitz网址:

这是我的密码

app.component.ts

从'@angular/core'导入{Component,OnInit};
从“jquery”导入美元;
@组成部分({
选择器:“我的应用程序”,
templateUrl:“./app.component.html”,
样式URL:['./app.component.css']
})
导出类AppComponent{
名称='角度';
恩戈尼尼特(){
//SampleJSONData是具有树结构的Json
变量comboTree1,comboTree2;
$(文档).ready(函数($){
comboTree2=$('#justanortherInputBox')。comboTree({
资料来源:SampleJSONData,
isMultiple:错误
});
});
}
}

单选

comboTree是jQuery的插件。你也需要安装它。从他们的网站下载comboTreePlugin.js并将其添加到您的项目中。 然后,您的app.component.ts在导入jquery后导入它

import { Component, OnInit } from '@angular/core';
import  $ from 'jquery';
import '../comboTreePlugin';  // enter proper path here, depending where you saved the plugin in your project.

... rest of your code ...
现在打开comboTreePlugin.js并在那里导入jquery:

import jQuery from 'jquery';

但编辑供应商包以在其中导入jquery并不是您应该做的事情。解决此问题更优雅的方法是:

  • 创建一个名为“globals.js”的文件(或任何你想命名的文件)
  • 在信中写下:

    import jquery from 'jquery';
    
    window.$ = jquery;
    window.jQuery = jquery;
    
  • 现在,在app.component.ts中,您的导入应该如下所示:

    import { Component,OnInit } from '@angular/core';
    import './globals';
    import '../comboTreePlugin';
    
    ... rest of your code ...
    
  • 它现在应该可以工作了,不需要在comboTreePlugin.js中编辑任何内容

    现在不需要在组件中导入jquery,因为导入globals将使
    $
    jquery
    都进入范围

  • Stackblitz:


    comboTree是jQuery的插件。你也需要安装它。从他们的网站下载comboTreePlugin.js并将其添加到您的项目中。 然后,您的app.component.ts在导入jquery后导入它

    import { Component, OnInit } from '@angular/core';
    import  $ from 'jquery';
    import '../comboTreePlugin';  // enter proper path here, depending where you saved the plugin in your project.
    
    ... rest of your code ...
    
    现在打开comboTreePlugin.js并在那里导入jquery:

    import jQuery from 'jquery';
    

    但编辑供应商包以在其中导入jquery并不是您应该做的事情。解决此问题更优雅的方法是:

  • 创建一个名为“globals.js”的文件(或任何你想命名的文件)
  • 在信中写下:

    import jquery from 'jquery';
    
    window.$ = jquery;
    window.jQuery = jquery;
    
  • 现在,在app.component.ts中,您的导入应该如下所示:

    import { Component,OnInit } from '@angular/core';
    import './globals';
    import '../comboTreePlugin';
    
    ... rest of your code ...
    
  • 它现在应该可以工作了,不需要在comboTreePlugin.js中编辑任何内容

    现在不需要在组件中导入jquery,因为导入globals将使
    $
    jquery
    都进入范围

  • Stackblitz:


    comboTree是jQuery的插件。你也需要安装它。我认为它不在npm上,所以你必须从他们的网站下载它的js,并将其导入你的app.component.ts是的,你是对的。它没有npm。那么你是如何在app.component.tsGetting中导入comboTree插件的导入错误在导入时找不到模块。在上面我共享了stackblitz链接。在你的stackblitz comboTreePlugin.js中是空的,里面没有写任何东西。确保正确下载。comboTree是jQuery的插件。你也需要安装它。我认为它不在npm上,所以你必须从他们的网站下载它的js,并将其导入你的app.component.ts是的,你是对的。它没有npm。那么你是如何在app.component.tsGetting中导入comboTree插件的导入错误在导入时找不到模块。在上面我共享了stackblitz链接。在你的stackblitz comboTreePlugin.js中是空的,里面没有写任何东西。请确保正确下载。谢谢,你挽救了这一天。啊,没关系,你最终会获得声誉。银行,你挽救了这一天。啊,没关系,你最终会获得声誉