angularjs - 实现 ng2-completer

标签 angularjs autocomplete

我目前正在为 angular 2 使用 ng2-completer ( https://github.com/oferh/ng2-completer ),并努力添加建议以获得完整的响应,而不是只有一个值。

此外,当建议被选中时,分配的方法是如何处理的?

到目前为止我得到的代码是:

import { Component } from '@angular/core';
import { AutoComplete } from './autocomplete';
import { CompleterService, CompleterData, RemoteData } from 'ng2-completer';
import { SearchComponent } from './search.component';
import { QueryService } from './query.service';


@Component({
  selector: 'app-home',
  template: `<ng2-completer [(ngModel)]="searchStr" [dataService]="dataService" [minSearchLength]="0" [inputClass]="['form-control input-list']" [autofocus]="['true']" [selected]="selected()"></ng2-completer>`,
  //directives: [ AutoComplete ]
})

export class HomeComponent {

  public searchStr: string;
  private dataService: CompleterData;

  constructor(private completerService: CompleterService, private queryService: QueryService) {
    //this.dataService = completerService.local(this.searchData, 'color', 'color');
    this.dataService = completerService.remote('http://localhost:61227/machine/?query=','ComputerHostname, AssetID', 'ComputerHostname').descriptionField('ComputerType');

//this.dataService = this.queryService.search(searchStr).then(items => this.items = items);  

}

selected () {

console.log("test");

}
 }

但是它显示以下错误:

无法绑定(bind)到“selected”,因为它不是“ng2-completer”的已知属性。

最佳答案

selected 是一个事件而不是属性,因此它的语法(如 Angular template syntax 中所述)应该是 (selected)="selected($event)"

autofocus 需要一个 bool 值 ( see in ng2-completer doc ) 而不是数组,因此您应该使用 [autofocus]="true"

关于angularjs - 实现 ng2-completer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42186950/

相关文章:

python - PyCharm 自动完成导入模块

autocomplete - Netbeans7.1 和 JavaFX 2.0 - FXML 代码完成不起作用

javascript - 可以在没有 REST API 的情况下使用 AngularJS 吗?

javascript - 内容丰富且 javascript : get only entries with fields. future 日期

java - 使用 Angular js 显示图像

javascript - Dojo 问题 : FilteringSelect , 需要 : "false" , 不工作

objective-c - 100000 个对象 : How to autocomplete in an NSTextField fast

jQueryUI 自动完成 : how to use 'first-of-type' and 'last-of-type' with #ui-active-menuitem?

javascript - 从重复值中过滤具有唯一值的对象数组

javascript - 如何在 ng-if AngularJS 中使用 JavaScript?