Skip to content

Instantly share code, notes, and snippets.

@raphaelluiz128
Last active April 6, 2018 17:46
Show Gist options
  • Save raphaelluiz128/8a7329f1cd9ded6cdcdd2a3dc9fbfa4d to your computer and use it in GitHub Desktop.
Save raphaelluiz128/8a7329f1cd9ded6cdcdd2a3dc9fbfa4d to your computer and use it in GitHub Desktop.
Json externo
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import {Http, Response} from '@angular/http';
import {DatabaseProvider} from '../../providers/database/database';
import 'rxjs/add/operator/map';
import { NgForOf } from '@angular/common';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
private url:string='http://www.cafepedraelefantina.com.br/medicao/medicaoPorci.json';
public medicoes:Array<{}>;
dataMedicoes: any
selectedItem: any;
constructor(public navCtrl: NavController,private database:DatabaseProvider,public navParams: NavParams,
public http: Http) {
}
AtualizarMedicoes(){
// var url1: string ='http://www.cafepedraelefantina.com.br/medicao/medicaoPorci.json';
//this.http.get(url1)
this.http.get(this.url)
.map(res => res.json())
.subscribe(data =>{
this.medicoes = data.medicao;
//alert("ver my object data: "+ data.medicao[0].nivel);
//alert(data.medicao[0].nivel);
for(var i=0;i<data.medicao.length;i=i+1){
this.database.CreateMedicao(data.medicao[i].data,data.medicao[i].hora,data.medicao[i].nivel);
}
//alert(data.medicao[0].data);
//alert(data.medicao[0].hora);
})
//this.database.DeletarDados();
// this.database.DeletarDados();
// this.GetAllMedicoes();
}
/*
CreateMedicao(){
var datam="12",horam="13",nivelm="56";
this.database.CreateMedicao(datam,horam,nivelm).then
((data) => { console.log(data);
}, (error) => {
console.log(error);
})
}
*/
/*
vaParaTestPage(){
this.navCtrl.push(TestPage);
}
*/
GetAllMedicoes(){
// this.database.DeletarDados();
this.database.GetAllMedicoes().then
((data) => { this.dataMedicoes = data;
console.log(data);
//console.log(this.database.arrayMedicoes);
//console.log(this.database.arrayMedicoes[0].ID);
}, (error) => {
console.log(error);
})
}
itemClick() {
alert(this.medicoes[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment