I'm busy working on an AngularJS application which gets data from an API. However I'm wondering if there's a possibility to directly invoke a function in the scope AND call it normally.
This is what I have in my controller:
var self = this;
$scope.refreshData = (function() {
$http({
method: 'GET',
url: './test-api/testdata.php'
})
.success(function(data) {
self.apiData = data;
});
console.log('Refresh executed');
})();
$interval(function() {
console.log('Refresh called');
$scope.refreshData();
}, 60000);
This logs:
Refresh executed
angular.js:13540 TypeError: $scope.refreshData is not a function
I know I can just change it to a normal function and call it with $scope.refreshData()
, but I was just wondering if there's a method for it in AngularJS.