Below is the controller code:
app.controller('myCtrl', function($scope, $http, $timeout) {
$scope.getData = function() {
$http.get("../send")
.then(function(response) {
$scope.text = response.data;
$scope.params = $scope.text.split(' ');
$scope.timeFunc();
},
function(response) {
$scope.timeFunc();
});
};
$scope.timeFunc = function() {
$timeout(function() {
$scope.getData();
}, 1000);
};
$scope.getData();
});
Is there a way to move this functionality out of the controller and into a separate service?
The challenge here is to ensure that the variable params
is updated every second.