2017-02-12 4 views
3

私は現在、角度2にng2-completer(https://github.com/oferh/ng2-completer)を使用しています。ただ1つの値を持つ代わりに、完全な応答を得るための提案を追加するのに苦労しています。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"); 

} 
} 

それは次のようなエラーが表示さしかし:それは、既知のプロパティではありませんので、

は、「選択」にバインドできませんng2-completer 'を選択します。

答えて

0

selectedは、イベントやない財産であり、そのための(Angular template syntaxで説明したように)それのための構文は(selected)="selected($event)"

autofocusする必要がありますあなたが[autofocus]="true"

を使用する必要がありますので、ブール値( see in ng2-completer doc)でない配列を期待