Using the https://github.com/ironboy/mongresto framework, I have an angularjs directive with html and js. The problem is the Assignment.get is looping 2000+ times which makes me think something is wrong with my implementation of ng-if as this calls the scope.hasAssignment. Or maybe im looking in the wrong place
assignments.html
<!--Assignments-->
<li ng-if = "hasAssignment(course.assignments)"><a ng-click="isChildOpen = !isChildOpen">Assignments <i ng-hide="isChildOpen" class="fa--toggle fa fa-chevron-right"></i><i ng-show="isChildOpen" class="fa--toggle fa fa-chevron-down"></i></a>
<ul ng-show="isChildOpen" ng-repeat="assignment in assignmentlist">
<li><a href="courses/{{course.name}}/assignment/{{ assignment._id }}"><i class="fa--itemtype fa fa-file-text-o"></i>{{assignment.name}}</a></li>
</ul>
assignments.js
scope.hasAssignment = function(assignmentArray)
{
if(typeof assignmentArray !== 'undefined' && assignmentArray.length > 0)
{
Assignment.get({course: scope.course._id}, function(res){
scope.assignmentlist = res;
});
return true;
}
else
{
return false;
}
}
I used a console log on the assignmentArray passed into the function and it returns an array of 3 assignments. The functionality works in the end, and the list gets filled with results from the db its just it keeps running forever.
hasAssignmentinside ng-if` which is getting call on each digest cycle, from that function you are again callingAssignment.getwhich again run an digest cycle once it get completed.. so this is scenario is happening infinite amount of time & that is causing an error