我正在创建一个服务来将值保存为" FirstName"在一行"名称",当保存是好的我有数据库中的值,但当我尝试得到这个值我有这样的东西:
列表中的所有值都为空,但我不知道为什么在控制器或服务中出现问题时会发生这种情况。
<script src="https://www.parsecdn.com/js/parse-1.3.2.min.js"></script>
<div ng-app="app">
<ul ng-controller="MyCtrl">
people
<li ng-repeat="person in people">{{person}}</li>
</ul>
</div>
<script type="text/javascript">
Parse.initialize("key", "key");
var People = Parse.Object.extend("People");
var peoples= new People();
peoples.set("name", "FirstName");
peoples.save(null),{
success:function(peoples){
peoples.save();
}
}
var app = angular.module('app', []);
app.controller("MyCtrl", ["$scope", "PeopleService", function($scope, PeopleService){
$scope.people = PeopleService.getPeople();
}]);
app.service("PeopleService", function($q){
var people = null;
return {
getPeople: function(){
var deferred = $q.defer();
people = [];
var queryObject = new Parse.Query(People);
queryObject.find({
success: function (results) {
for (var i = 0; i < results.length; i++) {
var result = results[i];
people.push(result.get("name"));
}
deferred.resolve(people);
},
error: function (error) {
deferred.reject(error);
}
});
return deferred.promise;
}
}
});
</script>
答案 0 :(得分:1)
您应该从parse.com
来电的成功回调功能中设置app.controller("MyCtrl", ["$scope", "PeopleService", function($scope, PeopleService){
PeopleService.getPeople().then(function(data){ //success fn
$scope.people = data
},function(data){ //error fn
$scope.people = data
});
}]);
值。
<强>代码强>
{{1}}