Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ngOnInit() {
- this.jsonUrl = 'mycustomerurl';
- let that = this;
- let options = this.createRequestHeader();
- this.autocomplete.autoCompleteTextView.loadSuggestionsAsync = function (text) {
- const promise = new Promise(function (resolve, reject) {
- http.request({
- url: this.jsonUrl + '/' + text,
- method: "GET",
- headers: options,
- }).then(function (r: any) {
- console.error(r);
- const myData = r;
- const items: Array<TokenModel> = new Array();
- for (let i = 0; i < myData.length; i++) {
- items.push(new TokenModel(myData[i].label, null));
- }
- resolve(items);
- }).catch((err) => {
- const message = 'Error fetching remote data from ' + that.jsonUrl + ': ' + err.message;
- console.log(message);
- alert(message);
- reject();
- });
- });
- return promise;
- };
- }
- private createRequestHeader() {
- // set headers here e.g.
- const tokenInfo = appSettings.getString('TokenInfo');
- let headers = new HttpHeaders({
- Authorization: `Bearer ${tokenInfo}`,
- "Content-Type": "application/json",
- });
- return headers;
- }
- [
- {
- "label": "GLOBAL AGENCIES LTD",
- "id": "P000003",
- "val": "100.00"
- },
- {
- "label": "NEW MARKETING LTD",
- "id": "P000004",
- "val": "200.00"
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement