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.