1

I have the following code which binds and displays date of the due_date. Actually I'm trying to bind the Due_date value into another input ng-module as another, so I have used the below given HTML coding.

My HTML:

<p><input type="text" data-ng-model="another" ng-bind="another=addDays(sryarndebitnote.invoice_date, sryarndebitnote.terms) | date:'dd-MM-yyyy'"></p>

My controller:

 $scope.addDays = function(stringDate, days) {
   var date = new Date(stringDate);
   date.setDate(date.getDate() + parseInt(days));
  return date;
}

When I run the above code, I get the following error:

Error: Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: ngModelWatch; newVal: \"2016-08-22T00:00:00.000Z\";

I have created Plunker for reference: My plunker

Ideas of why I'm getting this error?

Alex M
  • 2,756
  • 7
  • 29
  • 35
R. Mani Selvam
  • 320
  • 8
  • 36
  • 1
    http://stackoverflow.com/questions/14376879/error-10-digest-iterations-reached-aborting-with-dynamic-sortby-predicate – RIYAJ KHAN Aug 12 '16 at 12:22
  • hi thanks for your comment , please look my controller and html codes and help to me, i already seen that above given question and answer and i have used `$scope.$watch('users', function(value) { $scope.users = []; });` this code too, it's not working for me so please help for the same – R. Mani Selvam Aug 12 '16 at 12:26
  • no worry.I will check your code – RIYAJ KHAN Aug 12 '16 at 12:40
  • What is the meaning of this `due_date=addDays(sryarndebitnote.invoice_date,sryarndebitnote.terms)`? – RIYAJ KHAN Aug 12 '16 at 12:44
  • Sorry buddy now you see my plunk :-http://plnkr.co/edit/DMrh5XAeMYnjgWgCC5iq?p=preview it's for another=addDays(name.invoice_date,name.terms) i got the ng-bind answer like this:- Tue Sep 06 2016 05:30:00 GMT+0530 (IST) – R. Mani Selvam Aug 12 '16 at 12:53
  • then i'm looking the answer like date format, and also got the above mentioned error, please help to solve the error.. – R. Mani Selvam Aug 12 '16 at 12:57

1 Answers1

0

Instead of using ng-model and ng-bind together, What you should do is as you are using ng-bind only for initializing another. Instaed use ng-init. Like this:

function AngularCtrl($scope) {
   $scope.predicate = 'score';
   $scope.reverse = true;
    
     $scope.addDays = function(stringDate,days) {
   var date = new Date(stringDate);
   date.setDate(date.getDate() + parseInt(days));
  return date;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="AngularCtrl" ng-app>
        <input type="text"  data-ng-model="another" ng-init="another=addDays('Fri Aug 12 2016 18:06:22',5)  | date:'dd-MM-yyyy'" style="width:400px;" >
</div>

In the code have taken some random date just for demo purpose you can pass your own values. Here is the working fiddle link. Hope it helps.

Manish
  • 4,692
  • 3
  • 29
  • 41
  • hi thanks for your comment , now i'm given the plunker :- http://plnkr.co/edit/vrOI6fLdt58PnnGvudvm?p=preview i have used your coding but again the error is showing , so can u please make a edit in plunker and update? – R. Mani Selvam Aug 12 '16 at 13:29
  • i checked out your plunker it seems to work fine . There was error in markup that i corrected. Here is the snapshot https://postimg.org/image/fiwf7pad1/. have upadted the plunker http://plnkr.co/edit/Pbj2sac633VlcIcO3qIc?p=preview – Manish Aug 12 '16 at 14:49
  • hey hi if i used the `ng-init` to my codes it's showing error like:- `invalid date` , then same above mentioned error is displaying in my `console` so please let us know using of `ng-bind` to resolve this issue.... sorry to trouble you...! http://plnkr.co/edit/R1Qn8X1XZel5pZqvaBmM?p=preview – R. Mani Selvam Aug 13 '16 at 11:00
  • click inspect elements in pluncker and look at the console their displaying the error...thanks – R. Mani Selvam Aug 13 '16 at 11:02
  • http://stackoverflow.com/questions/14376879/error-10-digest-iterations-reached-aborting-with-dynamic-sortby-predicate In this post its mentioned that **You shouldn't change objects/models during the render or otherwise it will force a new render (and consequently a loop, which causes the 'Error: 10 $digest() iterations reached. Aborting!').** . I suggest to initialize **another** in controller not while render. use $watch to filter date using $filter. Have updated the plunker now its not showing the error. http://plnkr.co/edit/jio41zdJyGOylllbv4YN?p=preview Hope it helps. – Manish Aug 16 '16 at 11:55