I am working on Angularjs ui grid and I want to refresh the data in the grid every 1 min. Hence I used $interval to fire a function which would fetch the data and the output of he function needs to be bind to the ui-grid.
Without the use of $interval, the function output binds successfully to grid (although without refresh every 1 min!). However, with $interval, the output does not bind to grid.
Below is my code,
var grdDataPromise;
function GetData() {
return InfoDataService.getDummyDetails($scope.getDtToday(), 'ABC', 'PQR');
}
$scope.startGetData = function () {
$scope.stopGetData();
grdDataPromise = $interval(GetData, REFRESH_RATE);
grdDataPromise.then(function (result) {
$scope.gridOptionsDashBoard.data = result;
});
}
$scope.startGetData();
$scope.stopGetData = function () {
$interval.cancel(grdDataPromise);
}
$scope.$on('$destroy', function () {
$scope.stopGetData();
});
Here, the grdDataPromise.then() function never fires, which I believe is the problem, but I am unable to find a fix for this issue.
Can anyone suggest how can I make the data bind to the grid after the function executes every 1 minute interval?
Thanks in advance.