NativeScript ui自动完成未定义属性

NativeScript ui自动完成未定义属性,nativescript,nativescript-angular,nativescript-telerik-ui,nativescript-plugin,Nativescript,Nativescript Angular,Nativescript Telerik Ui,Nativescript Plugin,可能是个愚蠢的问题,但我正在尝试获取远程数据以在nativescript ui自动完成中使用,但我得到以下错误错误类型错误:无法设置未定义的属性“LoadSuggestionAsync” 代码非常类似于的例子,但我不能让我的工作 打字稿 import * as http from "tns-core-modules/http"; import { ObservableArray } from "tns-core-modules/data/observable-array"; import {

可能是个愚蠢的问题,但我正在尝试获取远程数据以在nativescript ui自动完成中使用,但我得到以下错误
错误类型错误:无法设置未定义的属性“LoadSuggestionAsync”

代码非常类似于的例子,但我不能让我的工作

打字稿

import * as http from "tns-core-modules/http";

import { ObservableArray } from "tns-core-modules/data/observable-array";
import { TokenModel } from "nativescript-ui-autocomplete";
import { RadAutoCompleteTextViewComponent } from "nativescript-ui-autocomplete/angular";

export class MapComponent implements OnInit {

    private _items: ObservableArray<TokenModel>;
    private jsonUrl = "https://raw.githubusercontent.com/NativeScript/nativescript-ui-samples/master/examples-data/airports.json";

    mapbox: MapboxViewApi; 

    constructor( private router: Router) {
        // Use the component constructor to inject providers.
    }

    ngOnInit() {
        let that = this;
        this.autocomplete.autoCompleteTextView.loadSuggestionsAsync = function (text) {
            const promise = new Promise(function (resolve, reject) {
                http.getJSON(that.jsonUrl).then(function (r: any) {
                    const airportsCollection = r.airports;
                    const items: Array<TokenModel> = new Array();
                    for (let i = 0; i < airportsCollection.length; i++) {
                        items.push(new TokenModel(airportsCollection[i].FIELD2, null));
                    }

                    resolve(items);
                }).catch((err) => {
                    const message = 'Error fetching remote data from ' + that.jsonUrl + ': ' + err.message;
                    console.log(message);
                    alert(message);
                    reject();
                });
            });

            return promise;
        };

    }

    @ViewChild("autocomplete", { static: true }) autocomplete: RadAutoCompleteTextViewComponent;

    get dataItems(): ObservableArray<TokenModel> {
        return this._items;
    }
}
请尝试ngAfterViewInit()。最初渲染视图后,将调用ngAfterViewInit()。这就是@ViewChild()依赖它的原因

ngAfterViewInit() {
        let that = this;
        this.autocomplete.autoCompleteTextView.loadSuggestionsAsync = function (text) {
            const promise = new Promise(function (resolve, reject) {
                http.getJSON(that.jsonUrl).then(function (r: any) {
                    const airportsCollection = r.airports;
                    const items: Array<TokenModel> = new Array();
                    for (let i = 0; i < airportsCollection.length; i++) {
                        items.push(new TokenModel(airportsCollection[i].FIELD2, null));
                    }

                    resolve(items);
                }).catch((err) => {
                    const message = 'Error fetching remote data from ' + that.jsonUrl + ': ' + err.message;
                    console.log(message);
                    alert(message);
                    reject();
                });
            });

            return promise;
        };

    }
ngAfterViewInit(){
让那=这;
this.autocomplete.autoCompleteTextView.LoadSuggestionAsync=函数(文本){
常量承诺=新承诺(函数(解析、拒绝){
http.getJSON(that.jsonUrl).then(函数(r:any){
const airports集合=r.机场;
常量项:数组=新数组();
for(设i=0;i{
const message='从'+that.jsonUrl+'获取远程数据时出错:'+err.message;
控制台日志(消息);
警报(信息);
拒绝();
});
});
回报承诺;
};
}
尝试ngAfterViewInit()。最初渲染视图后,将调用ngAfterViewInit()。这就是@ViewChild()依赖它的原因

ngAfterViewInit() {
        let that = this;
        this.autocomplete.autoCompleteTextView.loadSuggestionsAsync = function (text) {
            const promise = new Promise(function (resolve, reject) {
                http.getJSON(that.jsonUrl).then(function (r: any) {
                    const airportsCollection = r.airports;
                    const items: Array<TokenModel> = new Array();
                    for (let i = 0; i < airportsCollection.length; i++) {
                        items.push(new TokenModel(airportsCollection[i].FIELD2, null));
                    }

                    resolve(items);
                }).catch((err) => {
                    const message = 'Error fetching remote data from ' + that.jsonUrl + ': ' + err.message;
                    console.log(message);
                    alert(message);
                    reject();
                });
            });

            return promise;
        };

    }
ngAfterViewInit(){
让那=这;
this.autocomplete.autoCompleteTextView.LoadSuggestionAsync=函数(文本){
常量承诺=新承诺(函数(解析、拒绝){
http.getJSON(that.jsonUrl).then(函数(r:any){
const airports集合=r.机场;
常量项:数组=新数组();
for(设i=0;i{
const message='从'+that.jsonUrl+'获取远程数据时出错:'+err.message;
控制台日志(消息);
警报(信息);
拒绝();
});
});
回报承诺;
};
}

也有同样的问题,就我而言,我必须更换

 this.autocomplete.*autoCompleteTextView*.loadSuggestionsAsync = function (text) {


希望对您有所帮助。

也有同样的问题,就我而言,我不得不更换

 this.autocomplete.*autoCompleteTextView*.loadSuggestionsAsync = function (text) {


希望对你有帮助。

就我而言。我将组件声明向上移动到一个模块。这很有帮助。也许它需要一些特殊的模块,但我在文档中没有找到任何信息。

在我的例子中。我将组件声明向上移动到一个模块。这很有帮助。可能它需要一些特殊的模块,但我在文档中找不到任何信息。

你能分享一个游乐场示例,在那里可以重现该问题。@Manoj更新了原始postLooks错误是从警报对话框本身引发的。如果你评论所有对话框或者用日志替换它,你仍然会看到同样的错误?@Manoj是的,这是我写的try/catch的问题,不再发生。奇怪的是,我将示例中的代码复制到了Playerd中,效果很好。我下载游乐场并在本地运行,效果很好。我用tns创建了一个新的angular应用程序创建并复制了代码,但不起作用。您能否共享一个游乐场示例,在该示例中可以重现该问题。@Manoj更新了原始postLooks错误是从警报对话框本身引发的。如果你评论所有对话框或者用日志替换它,你仍然会看到同样的错误?@Manoj是的,这是我写的try/catch的问题,不再发生。奇怪的是,我将示例中的代码复制到了Playerd中,效果很好。我下载游乐场并在本地运行,效果很好。我用tns创建了一个新的angular应用程序创建并复制代码,但不起作用。
this.autocomplete.**nativeElement**.loadSuggestionsAsync = function (text) { //etc