0

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";
    }
}
}
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • you never set estado to a string, so it is always undefined – Charlie Ng Dec 13 '17 at 23:24
  • It would be better that you crystallize your problem and demonstrate it by minimum code segment in your question. You've already done most of the work in your embedded screen capture. But your posting the relevant code in the question would enable a reader to answer your question with even less friction. Sorry, I have not code in Javascript for a while that I'm not able to provide a definite answer. – Yu Shen Dec 13 '17 at 23:25
  • thanks @YuShen! and thanks @Charlie but could you give me an example please? – Ricardo Dec 14 '17 at 03:00
  • I'd suggest you remove the jQuery, there is no need for it here. You are using Angular, so use Angular ;) – AT82 Dec 14 '17 at 06:36

0 Answers0