When working with AngularJS, I have a scenario where I am using ng-show="isChecked('ID')"
in an element to access a $rootScope array that is generated in another controller. Here's my function:
$scope.isChecked = function(ID) {
console.log( $rootScope.IsCntrChecked);
var mycheck = $rootScope.IsCntrChecked.find(function(v) {
return v.CntrCode == ID;
}).CntrChk;
console.log(mycheck);
return mycheck;
};
Everything works fine, except that initially I get error messages in the console saying "TypeError: Cannot read property 'find' of undefined" for the first few calls when $rootScope.IsCntrChecked is undefined. I tried using promises in the function to handle this, but it resulted in an error.
[$rootScope:infdig] 10 $digest() iterations reached. Aborting!
I would appreciate your suggestions on how to handle this error in a simple way. Thank you.