Skip to content

Instantly share code, notes, and snippets.

@apuravchauhan
Last active November 12, 2017 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apuravchauhan/70232cc65b76e72b0412326c11a9756b to your computer and use it in GitHub Desktop.
Save apuravchauhan/70232cc65b76e72b0412326c11a9756b to your computer and use it in GitHub Desktop.
Part 2 - Backend integration with Air pollution app - home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import { LoadingController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public loader: LoadingController, public navCtrl: NavController, public http: Http, ) {
this.http = http;
this.loader = loader;
this.aqi = { data: {} };
this.reload();
}
reload() {
let loading = this.loader.create({
spinner: 'dots',
content: 'Loading',
duration: 60000
});
this.http.get(`https://api.waqi.info/feed/here/?token=demo`)
.toPromise()
.then(response => {
this.aqi = response.json();
loading.dismiss();
})
.catch(error => {
loading.dismiss();
console.log(error.json())
let eloading = this.loader.create({
content: 'Connectivity Issue!',
duration: 5000
});
eloading.present();
});
}
aqiStatus(val) {
if (val <= 50) {
return { code: 'good', val: 'Good' };
} else if (val <= 100) {
return { code: 'mod', val: 'Moderate' };
} else if (val <= 200) {
return { code: 'unhealthy', val: 'Unhealthy' };
} if (val <= 300) {
return { code: 'vunhealthy', val: 'Very Unhealthy' };
} else if (val > 300) {
return { code: 'hazardous', val: 'Hazardous' };
} else {
return { code: '', val: '' }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment