Skip to content

Instantly share code, notes, and snippets.

@thivatm
Last active February 1, 2019 15:18
Show Gist options
  • Save thivatm/2ff6af3a6aa254b47b7fd7b42c2d209e to your computer and use it in GitHub Desktop.
Save thivatm/2ff6af3a6aa254b47b7fd7b42c2d209e to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { CurrencyService } from "../service/cu-service";
import { WheelSelector } from '@ionic-native/wheel-selector';
import { HttpClient } from '@angular/common/http';
import { isNumber } from 'ionic-angular/umd/util/util';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
countryCodes = [];
countryNames = new Map();
resultRate: any;
swappedRate: any;
fromValue: any;
toValue: any;
fromCurr: any = 'USD'; // default values
toCurr: any = 'LKR'; // default values
constructor(public navCtrl: NavController, protected cuService: CurrencyService, public http: HttpClient) {
}
ngOnInit() {
this.fetchCountries();
this.getCurrencyRate();
}
/* An asynchronous function which retrieves
CountryCode List
*/
async fetchCountries() {
try {
const res = await this.cuService.getCountries();
for (let x in res['results']) {
this.countryCodes.push(x);
this.countryNames.set(x, res['results'][x].currencyName);
}
} catch (err) {
console.error(err);
}
console.log(this.countryNames);
}
async getCurrencyRate() {
let from = this.fromCurr;
let to = this.toCurr;
try {
const exchangeRate = await this.cuService.getExchangeRate(from, to);
let rate = exchangeRate[from + "_" + to].val;
this.resultRate = rate;
}
catch (err) {
console.error(err);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment