3

我知道我是否需要在 angular 1.3 或 1.4 中使用 3rd 方库。我需要对那个东西做出指令并在我们的项目中使用它。现在我正在使用angular 2.0。我想在angular 2 https://jqueryui .com/autocomplete/ 或这个 https://jsfiddle.net/2rgrmv4q/

我可以jqueryangular2.

1.我将如何在角度使用 3rd 方库。

2.我如何在角度2中自动完成jquery。

这是我的代码 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() { }
 } 
4

2 回答 2

2

您只需要声明一个变量并输入值或使用您需要的值初始化该变量。在构造函数中,您必须定义Jquerypart 。看看这个。Autocomplete这是你需要的工作示例

http://plnkr.co/edit/dAMQc0EN6rSS4dEuTR7E?p=preview

只需将此代码放入构造函数中:

export class AppComponent { 
  availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",...
    ];
  constructor(){
    $( "#tags" ).autocomplete({
      source: this.availableTags
    });
  }
}
于 2016-02-14T12:57:42.157 回答
2

如果你不关心 jQuery 类型,你可以声明 $:

import {Component, ElementRef,Directive, EventEmitter,Output} from 'angular2/core';

declare var $: any;

如果你正在寻找打字,你可以关注这个帖子:

在 Angular 2 应用程序中使用 jQuery globaly

于 2016-02-14T14:47:41.607 回答