I'm using Ionic to create an app, and in the controller, I'm getting an object that's resolved from the app.js. This object has several properties including an array like so:
{
"objectId":"id",
"objectName":"name",
"anArray":[{
"id":"id1",
"name":"name1",
"description":"Medium Rare",
"photographUrl":"/image1"
}, {
"id":"id2",
"name":"name2",
"description":"Baked Beans on Scrumptious Dark Rye Bread",
"photographUrl":"/image2"
}],
"emptyArray":[]
}
However, the problem is, I can iterate through each item in the array in the html using: (key, value) in theObject.anArray, but in the controller, I'm trying to iterate through the array in a for loop
for (var i = 0; i < $scope.theObject.anArray.length; i++) {...}
However, I get an error:
TypeError: Cannot read property 'length' of undefined
Can anyone help me figure out why I cannot access this array in the controller, but I can in the html.
P.S. in the controller I use this:
$scope.theObject = theObject;
Thanks