how to $interval call function with parameter
$interval( getrecordeverytime(2), 100000);
function getrecordeverytime(contactId)
{
console.log(contactId + 'timer running');
}
You can pass parameters starting from fifth argument of $interval:
angular.module('app', []).controller('ctrl', function($scope, $interval){
function getrecordeverytime(contactId, second) {
console.log(`${contactId}, ${second} timer running`);
};
$interval(getrecordeverytime, 1000, 0, true, 2, 5);
})
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<div ng-app='app' ng-controller='ctrl'>
</div>
Alternatively you can create a function that returns the interval callback function, and have the parameter bound to the callback through closure. Like this:
function createRecordCallback(contactId){
return function(){
console.log(contactId + 'timer running'); // the value of contactId, will be bound to this function.
};
}
$interval(createRecordCallback(1234), 100000);
This is merely meant as an alternative. I do recommend Slava's answer in most cases.