In my project demo, I have implemented a feature that fetches data from the server at regular intervals using $interval
. Now, I am looking for a way to stop or cancel this process. Can you guide me on how to achieve this? And if I need to restart the process, what is the best approach?
Additionally, I have another query: while fetching data from the server periodically, do I need to use $scope.apply
or $scope.watch
? Your insights on this will be highly appreciated.
Check out my plunker below:
app.controller('departureContrl',function($scope,test, $interval){
setData();
$interval(setData, 1000*30);
function setData(){
$scope.loading=true;
test.stationDashBoard(function(data){
console.log(data);
$scope.data=data.data;
$scope.loading=false;
//alert(data);
},function(error){
alert('error')
}) ;
}
});