2017-09-14 108 views
0

我有一個自動完成場角2劍道UI自動完成不工作的數字

<kendo-autocomplete 
      [data]="postCodes" 
      [placeholder]="'Search for a PostCode'" 
      [suggest]="true" 
      (valueChange)="valueChange($event)" 
      [(ngModel)]="hospital" 
     > 

     </kendo-autocomplete> 

自動完成正常工作的字符串數組。 我想實現郵編的自動完成。儘管我將它聲明爲一個字符串數組,但它似乎沒有什麼區別。

我收到以下錯誤,當我在自動完成

AutoCompleteComponent.html:2 ERROR TypeError: this.suggestedText.toLowerCase is not a function 
    at AutoCompleteComponent.get [as suggestion] (autocomplete.component.js:160) 
    at Object.eval [as updateDirectives] (AutoCompleteComponent.html:7) 
    at Object.debugUpdateDirectives [as updateDirectives] (

選擇值我已經做了很多挖的,我似乎無法得到正確的答案。我甚至嘗試修改Number.prototype.toLowerCase在本Post

回答

2

當列表項目是實際的字符串自動完成,勢必提到,該組件似乎是按預期工作:

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    styles: ['.countries { width: 300px; }'], 
    template: ` 
    <div class="example-wrapper"> 
     <kendo-autocomplete 
      [data]="postCodes" 
      [placeholder]="'Search for a PostCode'" 
      [suggest]="true" 
      [(value)]="zipCode" 
     > 

     </kendo-autocomplete> 
     <hr /> 
     <pre>Selected code: {{zipCode}}</pre> 
    </div> 
    ` 
}) 
export class AppComponent { 
    public postCodes: Array<string> = [ 
    "1234", 
    "2345", 
    "9999" 
    ]; 

    public zipCode = ''; 
} 

WORKING

...而只有當項目是數字出現錯誤描述:

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    styles: ['.countries { width: 300px; }'], 
    template: ` 
    <div class="example-wrapper"> 
     <kendo-autocomplete 
      [data]="postCodes" 
      [placeholder]="'Search for a PostCode'" 
      [suggest]="true" 
      [(value)]="zipCode" 
     > 

     </kendo-autocomplete> 
     <hr /> 
     <pre>Selected code: {{zipCode}}</pre> 
    </div> 
    ` 
}) 
export class AppComponent { 
    public postCodes: Array<string> = [ 
    1234, 
    2345, 
    9999 
    ]; 

    public zipCode; 
} 

NOT WORKING/ERROR

確保AutoComplete綁定到的模型值通過ngModel綁定爲string類型,並且列表項也是字符串。

如果問題仍然存在,那麼共享類似的可運行示例(其中可以觀察到錯誤)將會很有幫助。

+0

謝謝。即使目標數組聲明爲Type Array,我也必須明確地將其轉換爲字符串