Guest User

Untitled

a guest
Jan 23rd, 2018
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Headers, Http } from '@angular/http';
  3. import "rxjs/add/operator/map";
  4. import "rxjs/add/observable/combineLatest";
  5. import { Observable } from 'rxjs/Observable';
  6. import * as Config from '../../config';
  7.  
  8.  
  9. @Injectable()
  10. export class CountryService {
  11. appSettings = require("application-settings");
  12.  
  13. constructor( private _apiEndpoints: Config.ApiEndpoints,
  14. private _http:Http,
  15. private _settings:Config.Settings) {
  16. }
  17.  
  18.  
  19. getPhonePrefix(): Observable<Object> {
  20. return this._http.get(this._apiEndpoints.apiEndpoint + '/country/phone')
  21. .map(res => res.json());
  22. }
  23.  
  24.  
  25. getCountryNameAndPrefix(): Observable<Array<Config.phonePrefix>> {
  26. return this.getPhonePrefix().combineLatest(this.getCountryName(),
  27. (phoneData, nameData) => {
  28. let resultData:Config.phonePrefix[] = [];
  29. Object.keys(nameData).forEach((key) => {
  30. let resultItem:Config.phonePrefix = {
  31. countrycode: key,
  32. countryname: nameData[key],
  33. countryprefix: phoneData[key]
  34. };
  35. resultData.push(resultItem);
  36. resultData.sort((a,b) => {
  37. if(a['countryname'] < b['countryname']) {
  38. return -1;
  39. } else {
  40. return 1;
  41. }
  42. });
  43. });
  44. return resultData;
  45. });
  46. }
  47. }
  48.  
  49. import "rxjs/add/operator/combineLatest";
Add Comment
Please, Sign In to add comment