While working on a Component HTML file, I encountered an issue with exposing a variable. The variable was supposed to retrieve a value from the response using cl.getMonitors
. Strangely, despite seeing console.dir(res)
in the console, the value of the variable Site.name
remained as 'Agenda'. Can someone provide assistance with this?
import { Component, OnInit } from '@angular/core';
import * as Client from 'uptime-robot';
const apiKey = 'asdasdasdasdasdasd';
const cl = new Client(apiKey);
var Site = {
name: 'Agenda',
status: ''
};
@Component({
selector: 'app-post',
templateUrl: './post.component.html',
styleUrls: ['./post.component.css']
})
export class PostComponent implements OnInit {
siteStatus: string;
siteName: string;
constructor() {
}
ngOnInit() {
cl.getMonitors({customUptimeRatio: [1, 7, 30]}, function (err, res) {
if (err) throw err;
console.dir(res);
this.siteName = res[0].friendlyname;
this.siteStatus = res[0].status;
});
this.siteName = Site.name;
this.siteStatus = Site.status;
}
}