2017-02-27 38 views
2

我無法使plugin與角度項目模板一起工作.GitHub僅顯示native和XML中的代碼.Sample插件代碼有效,但不幸的是沒有角度支持或幫助。我無法在角模板上顯示。 相關的代碼,我使用如何使用nativescript-autocomplete插件與nativescript角?

detail.component.ts

registerElement("AutoComplete",() => require("nativescript-autocomplete").AutoComplete); 

public list :Array = ['1','2','3','4','567'] ; 

public itemTapped(args){ 

console.log("tapped"); 

}

detail.component.html

<AutoComplete items=""{{list}}"" itemTap="itemTapped($event)"> </AutoComplete> 

我在控制檯收到異常,而頁面加載和自動完成不工作

this.items.forEach is not a function inside plugin code .that line is with definition of AutoComplete.prototype.itemsUpdate inside autocomplete.android.js plugin source 

調試到插件的源它打破了在初始化時:

'AutoComplete.prototype.itemsUpdate = function (items) { 
    var arr = Array.create(java.lang.String, this.items.length); 
    this.items.forEach(function (item, index) { 
     arr[index] = item; 
    }); 
    var ad = new android.widget.ArrayAdapter(app.android.context, android.R.layout.simple_list_item_1, arr); 
    this._android.setAdapter(ad); 
};' 
+0

你可能想看看nativescript-telerik-ui插件(https://www.nativescript.org/ui-for-nativescript)。它有一個免費版本和專業版本,其中包括一個AutoCompleteTextView組件。不幸的是,它不支持Angular,但它會在插件的下一個版本中。 –

回答

0

在detail.component.html

<AutoComplete [items]="list" (itemTap)="itemTapped($event)"> </AutoComplete> 
在details.component.ts

在NPM添加

public list:any= ['1','2','3','4','567'] ; 

itemTapped(ev){ 
//console.log(ev); your code 
} 

問題版。克隆repository

替換node_modules/nativescript-autocomplete中的所有文件,預計截圖,演示文件夾和git相關文件。並嘗試解決方案

+0

我忘了提及有問題的事件代碼。我更新了問題。此異常在頁面加載時在控制檯上靜默地引發。它沒有與事件相關。從插件本身的初始化部分出錯。 – Sadiq

+0

您是否應用了我的更改? – Habeeb

+0

只需要替換detail.component.html – Habeeb

相關問題