I am new to Angular and I am searching for a method to trigger a function only after the focus is out of the field, rather than after every change. The purpose of this function is to check if the user has modified the data in a specific <td>
element, and only execute the function in that case. The issue currently is that every keystroke triggers the function, causing it to run multiple times.
This is the table structure:
<tbody ng-repeat="(user_id, script_id) in data">
<tr ng-repeat="(script_id, cron_format) in script_id">
<td class="userName">{{user(user_id)}}</td>
<td class="scriptName">{{script(script_id)}}</td>
<td class="cronFormat"><input type="text" ng-model="cron_format" ng-change="saveCron(user_id, script_id, cron_format)"/></td>
</tr>
</tbody>
Below are the defined functions:
$scope.$watch('cron_format',function(x,old){
if(x!=old){
}
});
$scope.saveCron = function(userId, scriptId, cronFormat){
$.post("updateCronChange.php",
"user_id="+userId+"&script_id="+scriptId+"&cron_format="+cronFormat,
function(data){
//inside post
alert('Cron format changed to: '+cronFormat);
});
}
Is there any Angular-specific way to call the saveCron() function only when the focus moves out of the field (cron_format)?