0

I get an interpolation error but only sometimes. I refresh/load page a few hundred times without error or sometimes on first load it appears and shows up again after reloading/empyting cache etc. I cannot figure out what the source of the error is and why it seems to appear randomly.

Error: [$interpolate:interr] Can't interpolate: {{ showresult(all, two, figs, dates) }} TypeError: dates is undefined

It points to line 10023:

line 10017: if (hasApply) {
line 10018:    return function() {
line 10019:      var args = [];
line 10020:      forEach(arguments, function(arg) {
line 10021:       args.push(formatError(arg));
line 10022:           });
line 10023:          return logFn.apply(console, args);
line 10024:   };
line 10025: }

JavaScript:

$scope.showresult = function(all, two, figs, dates) {
    if(typeof(all) != undefined && typeof(two) != undefined && typeof(figs) != undefined && typeof(dates) != undefined){
         var lengthendtwo = 'start_' + two.name;
         var lengthenthree =  dates.text + '_' + figs.name;
         var datesproxy = Object.keys($scope.results[all.id][lengthendtwo])[dates.id];
         var result = angular.fromJson($scope.results[all.id][lengthendtwo][datesproxy][figs.name][lengthenthree]);
         return result;
     }
}

HTML:

<div ng-repeat="all in allz">
 ...
 <div ng-repeat="two in twoz">
  ...
   <div ng-repeat="figs in figsz">
    ...
     <div ng-repeat="dates in datesz">

       {{ showresult(all, two, figs, dates) }}

     </div>

   </div>

 </div>

</div>

EDIT: When replacing typeof(all) !== undefined with angular.isDefined(all) no error is given in the console anymore but results are either not shown at all or as "undefined", some are returned correctly. I think it could be a timing issue, the variables not being defined when function is called.

WORKAROUND: Instead of calling a function from the view, I build a scope variable (array) with same nested structure as the ng-repeat.

{{ showresult(all, two, figs, dates) }}

is replaced by

{{ showresult[$parent.$parent.$parent.$index][$parent.$parent.$index][$parent.$index][$index] }}

It works without an error but still would like to learn what was wrong with my original code.

chriscross
  • 413
  • 5
  • 18
  • the error states 'TypeError: dates is undefined' are you sure dates is defined ? – Nitsan Baleli Sep 28 '14 at 10:34
  • Yes. Error only occurrs sometimes. Otherwise results are correct. – chriscross Sep 28 '14 at 10:42
  • if you could show 'datesz' variable, or better yet, post a plunkr with your code – Nitsan Baleli Sep 28 '14 at 10:44
  • @Nitsan [JSFiddle](http://jsfiddle.net/tx12joxk/1/) (very simple). I have six of these muliple ng-repeats with different functions for each one but error is thrown for all or for none. TypeError: xyz is undefined, where xyz is not always "dates" – chriscross Sep 29 '14 at 12:40
  • you'd have to debug your code, use console.log to see the value of variables before they are 'repeated' in the html. – Nitsan Baleli Sep 29 '14 at 12:45
  • thx. jsut did that. value of variables looks fine. If I hardcode datesz (variable defined in controller instead of getting it from database) error is still the same. – chriscross Sep 29 '14 at 13:05
  • how can we reproduce your error? your JSfiddle is working ok – Nitsan Baleli Sep 29 '14 at 13:14
  • I have no idea. It seems to appear randomly, and so far only in Firefox. Haven't seen it in IE. Something browser specific/cache? – chriscross Sep 29 '14 at 13:17
  • maybe you post more code, and we'll try to refactor it. – Nitsan Baleli Sep 29 '14 at 13:45
  • OK, error also in IE now (not browser specific). @Nitsan you are right: console.log now shows undefined (still only sometimes). I tried $timeout and error changes from can't interpolate ... to only 'dates is undefined' – chriscross Sep 29 '14 at 15:36

0 Answers0