I'm trying to get a value from a service. I need to take this value and send to other service. The code is like this:
datameterId: string;
ngOnInit() {
this.graphCtrl.getMeter(this.id).subscribe(
response => {
this.ultimoValor = response["body"]["ultimoDatoConocido"];
this.ultimoValorCierre = response["body"]["ultimoDatoCierreMes"];
this.consumoMediaDiaria = response["body"]["consumoMedioDiario"];
this.consumoMediaMensual = response["body"]["consumoMedioMensual"];
this.consumoUltimoMes = response["body"]["consumoUltimoMes"];
this.alertas = response["body"]["alarmasActivas"];
this.contador = response["body"]["resumenDatameter"]["contador"];
this.datameterId = response["body"]["resumenDatameter"]["id"];
},
error => {
console.log(error);
}
);
this.config();
}
config() {
console.log(this.datameterId); //NULL
}
The problem: When I call another function the value lost, so i can´t use it. What´s is wrong in the code?
UPDATE
If i put this.config(); in the response returns
Cannot read property 'every' of undefined
at DaterangepickerComponent.push..
UPDATE 2
If i delete
this.ranges = {
Hoy: [moment(), moment()],
Ayer: [moment().subtract(1, "days"), moment().subtract(1, "days")],
"Últimos 7 días": [moment().subtract(6, "days"), moment()],
"Últimos 30 días": [moment().subtract(29, "days"), moment()],
"Este mes": [moment().startOf("month"), moment().endOf("month")],
"Mes pasado": [
moment()
.subtract(1, "month")
.startOf("month"),
moment()
.subtract(1, "month")
.endOf("month")
]
};
Doesn´t show error, but doesn´t works. Datarange need ranges to work.