I am working on an angularjs application which uses parse to create an array of names. I then pass that array to a controller, which I use in my html. My problem is that no data is coming through and I'm not sure why. I have tested my Parse connection, and it is working correctly, and I test my controller and it is passing data correctly. It is just when I combine the two that it stops working.
parse.js
function playerNames() {
Parse.$ = jQuery;
Parse.initialize("my key", "my key");
var names = new Array();
var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
query.find({
success: function (results) {
for (var i in results){
var name = results[i].get("playerName");
alert(name);
names.push(name);
}
return names;
},
error: function (error) {
alert(error.message);
return names;
}});
};
app.controller('NameController', ['$scope', function($scope) {$scope.names = playerNames()}]);
index.html
<div class="main" ng-controller="NameController">
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="n in names">
<td>{{ n }}</td>
</tr>
</tbody>
</table>
</div>
</div>
playerNames()
doesn't return anythingsuccess
callback does not return to outer function. Use$q
to create and return promise