如何使用角2 jQuery的? [英] how to use jquery in angular 2?
问题描述
我知道如果我我需要的角1.3或1.4。我需要使用第三方库做出的那个东西指令和使用,在我们的项目。现在我使用的角2.0 .I要让这个在角2
https://jqueryui.com/autocomplete/
或这个
https://jsfiddle.net/2rgrmv4q/
我可以使用的jQuery
在 angular2
。
1.How我将在角使用第三方库。
2.How我做的角2的jQuery自动完成。
这是我的code
http://plnkr.co/edit/BxMcNXLjVOJBAIiBGL5Y?p=$p$pview一>
// code放在这里
进口{组件,查看}从'angular2 /核心;
@零件({
选择:我的应用
templateUrl:家/ home.html做为',
})
出口类AppComponent {
构造函数(){}
}
您只需要声明一个变量,把值或用来初始化变量与您所需的值。在构造函数中,你必须定义 Jquery的
部分。看看this.Here工作示例自动完成
这是需要你
http://plnkr.co/edit/dAMQc0EN6rSS4dEuTR7E?p=$p$ PVIEW
块引用>只是把这个code到构造函数:
出口类AppComponent {
availableTags = [
动作,
AppleScript的
ASP
BASIC,...
];
构造函数(){
$(#tags).autocomplete({
来源:this.availableTags
});
}
}I know if i I need to use 3rd party library in angular 1.3 or 1.4 .I need to make directive of that thing and use that in our project .Now I am using angular 2.0 .I want to make this in
angular 2
https://jqueryui.com/autocomplete/ or this https://jsfiddle.net/2rgrmv4q/can I use
jquery
inangular2
.1.How I will use 3rd party library in angular.
2.How I make auto complete of jquery in angular 2.
here is my code http://plnkr.co/edit/BxMcNXLjVOJBAIiBGL5Y?p=preview
// Code goes here
import {Component,View} from 'angular2/core'; @Component({ selector:'my-app' templateUrl: 'home/home.html', }) export class AppComponent { constructor() { } }
解决方案You just need to declare one variable and put values or initilize that variable with the values that your required. in the constructor you have to define
Jquery
part . take a look at this.Here is working example forAutocomplete
which is required to youJust put this code into the constructor :
export class AppComponent { availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC",... ]; constructor(){ $( "#tags" ).autocomplete({ source: this.availableTags }); } }
这篇关于如何使用角2 jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!