首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实现NG2-完成器

实现NG2-完成器
EN

Stack Overflow用户
提问于 2017-02-12 19:21:23
回答 1查看 5.3K关注 0票数 3

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

另外,当建议被选择时,如何分配方法来处理它?

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

代码语言:javascript
复制
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");

}
 }

但是,它显示以下错误:

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

EN

回答 1

Stack Overflow用户

发布于 2017-02-19 20:55:38

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42186950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档