I have a controller in AngularJS
that retrieves objects from the backend using Parse
:
function MyController() {
var self = this;
var listObjects;
function fetchObjects() {
var myObject = Parse.Object.extend("MyObject");
var query = new Parse.Query(myObject);
query.find().then(function(objects) {
for (var i = 0; i < objects.length; i++) {
var object = objects[i];
self.listObjects.push(object);
}
}, function(error) {
console.log("ERROR: " + error);
});
}
fetchObjects();
self.fetchObjects = fetchObjects;
}
I am attempting to populate a <select>
element with these objects using:
<select ng-options="object.Name for object in myController.listObjects"></select>
The issue I'm facing is that listObjects
appears to be inaccessible within my function. When I try to log listObjects
, it returns as undefined. Is there a way to ensure that my <select>
dropdown is populated when the page loads? I've also tried triggering my function on an onLoad
event without success. Any suggestions or advice would be greatly welcomed.