-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathautocomplete-remote.component.ts
55 lines (47 loc) · 2.28 KB
/
autocomplete-remote.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// >> angular-autocomplete-getting-started-component
import { Component, ViewChild, OnInit } from "@angular/core";
import { ObservableArray } from "tns-core-modules/data/observable-array";
import { TokenModel } from "nativescript-ui-autocomplete";
import { RadAutoCompleteTextViewComponent } from "nativescript-ui-autocomplete/angular";
import http = require("tns-core-modules/http");
@Component({
moduleId: module.id,
selector: "tk-autocomplete-remote.component",
templateUrl: "autocomplete-remote.component.html"
})
export class AutoCompleteRemoteComponent implements OnInit {
private _items: ObservableArray<TokenModel>;
private countries = ["Australia", "Albania", "Austria", "Argentina", "Maldives", "Bulgaria", "Belgium", "Cyprus", "Italy", "Japan",
"Denmark", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland",
"Latvia", "Luxembourg", "Macedonia", "Moldova", "Monaco", "Netherlands", "Norway",
"Poland", "Romania", "Russia", "Sweden", "Slovenia", "Slovakia", "Turkey", "Ukraine",
"Vatican City", "Chad", "China", "Chile"];
ngOnInit() {
this.autocmp.autoCompleteTextView.loadSuggestionsAsync = function (text) {
var promise = new Promise(function (resolve, reject) {
http.getJSON("http://www.telerik.com/docs/default-source/ui-for-ios/airports.json?sfvrsn=2").then(function (r: any) {
var airportsCollection = r.airports;
var items: Array<TokenModel> = new Array();
for (var i = 0; i < airportsCollection.length; i++) {
items.push(new TokenModel(airportsCollection[i].FIELD2, null));
}
resolve(items);
}, function (e) {
reject();
});
});
return promise;
}
}
@ViewChild("autocmp") autocmp: RadAutoCompleteTextViewComponent;
get dataItems(): ObservableArray<TokenModel> {
return this._items;
}
private initDataItems() {
this._items = new ObservableArray<TokenModel>();
for (var i = 0; i < this.countries.length; i++) {
this._items.push(new TokenModel(this.countries[i], undefined));
}
}
}
// << angular-autocomplete-getting-started-component