im using ng-init in my app to initalize a variable. problem is i am changing this variable after app is loaded and i want the variable i first initialized to store new value after function executes. im new to angular and couldn't figure it out...
this is my ng-init
:
<tr ng-repeat="(script_id, cron_format) in row" **ng-init**="oldCron = cron_format">
<td>{{user_id}}</td>
<td>{{script_id}}</td>
<td>
<input type="text" ng-model="cron_format" ng-blur="saveCron(user_id,script_id,cron_format,oldCron)"/>
</td>
</tr>
and saveCron()
should change the value of oldCron
, but every time i call the function it initializes oldCron with the value in ng-init.
this is the function with my attempt to commit the change:
$scope.saveCron = function(userId,scriptId,cronFormat,oldCron){
if (oldCron != cronFormat) {
oldCron = cronFormat;
$http.post("updateCronChange.php",cron_format=" + cronFormat, function (data) {
alert('cron format changed to:' + cronFormat);
});
}
}
any idea how can i update oldCron
and ignor ng-init after first initialization??