我面对这样的错误。“错误:$(...)comboTree不是一个函数”。
我已经安装了jQuery,@类型/ jQuery的。 添加comboTree.js插件和icontainer.js。
Stackblitz网址:
https://stackblitz.com/edit/angular-pg3hjd
在这里我的代码是
app.component.ts
import { Component,OnInit } from '@angular/core';
import $ from 'jquery';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
ngOnInit() {
// SampleJSONData Be the Json with tree structure
var comboTree1, comboTree2;
$(document).ready(function($) {
comboTree2 = $('#justAnotherInputBox').comboTree({
source : SampleJSONData,
isMultiple: false
});
});
}
}
<div class="row">
<div class="col-lg-6">
<h3>Single Selection</h3>
<input type="text" id="justAnotherInputBox" placeholder="Type to filter"/>
</div>
</div>
comboTree是的jQuery插件。您需要安装太多。从他们的github下载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';
import jquery from 'jquery';
window.$ = jquery;
window.jQuery = jquery;
import { Component,OnInit } from '@angular/core';
import './globals';
import '../comboTreePlugin';
... rest of your code ...
$
和jQuery
到范围。Stackblitz: https://stackblitz.com/edit/angular-qswozq https://angular-qswozq.stackblitz.io