如何在 angular 2 中使用 jquery? [英] how to use jquery in angular 2?
问题描述
我知道我是否需要在 angular 1.3 或 1.4 中使用 3rd 方库.我需要对那个东西做出指令并在我们的项目中使用它.现在我正在使用 angular 2.0.我想在 angular 2
中做到这一点https://jqueryui.com/autocomplete/或这个https://jsfiddle.net/2rgrmv4q/
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/
我可以在 angular2
中使用 jquery
.
can I use jquery
in angular2
.
1.我将如何在 angular 中使用 3rd 方库.
1.How I will use 3rd party library in angular.
2.我如何在 angular 2 中自动完成 jquery.
2.How I make auto complete of jquery in angular 2.
这是我的代码http://plnkr.co/edit/BxMcNXLjVOJBAIiBGL5Y?p=preview
//代码放在这里
import {Component,View} from 'angular2/core';
@Component({
selector:'my-app'
templateUrl: 'home/home.html',
})
export class AppComponent {
constructor() { }
}
推荐答案
您只需要声明一个变量并使用您需要的值放置值或初始化该变量.在构造函数中,您必须定义 Jquery
部分.看看this.Here是Autocomplete
的工作示例,您需要
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 for Autocomplete
which is required to you
http://plnkr.co/edit/dAMQc0EN6rSS4dEuTR7E?p=preview
只需将此代码放入构造函数中即可:
Just put this code into the constructor :
export class AppComponent {
availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",...
];
constructor(){
$( "#tags" ).autocomplete({
source: this.availableTags
});
}
}
这篇关于如何在 angular 2 中使用 jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!