First I have to say that I am new on ionic, angular, typescript, and I don´t know the better way to do this project, so have mercy please.
I get a string from a txt file and save it on the variable estado
, then I want to use that string with another function but I only get undefined, some help please.
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import * as jQuery from 'jquery';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
estado: string;
estadoView: string = " deshabilitadas";
accionView: string = "Activar";
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
jQuery.get('http://localhost/estadoAlarma.txt', function (estado) {
console.log("ionviewdid");
console.log(estado);
return estado;
});
this.actAlarma(this.estado);
}
actAlarma(estado) {
console.log(estado); //here I get undefined
if (estado == "activado" ) {
console.log("si vale");
this.estadoView=" habilitadas";
this.accionView="Desactivar1";
}
else{
console.log("no vale");
this.estadoView=" deshabilitadas";
this.accionView="Activar";
}
}
}