这是基本代码。此代码将承诺传递给控制器,但我需要将结果对象返回给控制器。
openupServices.factory('getCurrentProject',
function($rootScope, $q, $location, $resource) {
var factory = {};
factory.getProject = function () {
var deferred = $q.defer();
var AppProject = Parse.Object.extend("AppProject");
var query = new Parse.Query(AppProject);
query.equalTo("userId", $rootScope.sessionUser.id);
query.find({
success: function(results) {
console.log(results);
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
return deferred.promise;
}
return factory;
});
openupControllers.controller('ProjectCtrl',
function($scope, $location, $rootScope, getCurrentProject) {
var thisProject = getCurrentProject.getProject();
});