Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. ngOnInit() {
  2. this.jsonUrl = 'mycustomerurl';
  3. let that = this;
  4. let options = this.createRequestHeader();
  5. this.autocomplete.autoCompleteTextView.loadSuggestionsAsync = function (text) {
  6. const promise = new Promise(function (resolve, reject) {
  7. http.request({
  8. url: this.jsonUrl + '/' + text,
  9. method: "GET",
  10. headers: options,
  11. }).then(function (r: any) {
  12. console.error(r);
  13. const myData = r;
  14. const items: Array<TokenModel> = new Array();
  15. for (let i = 0; i < myData.length; i++) {
  16. items.push(new TokenModel(myData[i].label, null));
  17. }
  18. resolve(items);
  19. }).catch((err) => {
  20. const message = 'Error fetching remote data from ' + that.jsonUrl + ': ' + err.message;
  21. console.log(message);
  22. alert(message);
  23. reject();
  24. });
  25. });
  26.  
  27. return promise;
  28. };
  29.  
  30. }
  31.  
  32. private createRequestHeader() {
  33. // set headers here e.g.
  34. const tokenInfo = appSettings.getString('TokenInfo');
  35. let headers = new HttpHeaders({
  36. Authorization: `Bearer ${tokenInfo}`,
  37. "Content-Type": "application/json",
  38. });
  39.  
  40. return headers;
  41. }
  42.  
  43. [
  44. {
  45. "label": "GLOBAL AGENCIES LTD",
  46. "id": "P000003",
  47. "val": "100.00"
  48. },
  49. {
  50. "label": "NEW MARKETING LTD",
  51. "id": "P000004",
  52. "val": "200.00"
  53. }
  54. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement