I'm building an angular app for the first time and I've got a controller which is used to monitor the health of a system. The health data comes from a rest api which I can hit and get the data successfully. I want to set this up to run every 5 minutes using setInterval. I can call the function once immediately to get the initial data but when the interval fires, I continue to get the error "Uncaught TypeError: Cannot read property 'one' of undefined". I believe I'm facing an out of scope situation but can't for the life of me figure out how to fix it. Here's the code:
class SystemHealthController {
/*@ngInject*/
constructor($scope, $interval, Rest) {
this.name = 'systemHealth';
this.$scope = $scope;
this.Rest = Rest;
this.getHealth();
setInterval(this.getHealth, 300000);
}
getHealth(){
this.Rest.one('getHealth.html?system=10021').get().then((response) => {
this.health = response;
console.log(this.health);
});
}
}
export default SystemHealthController;