I have a factory defined to make a parse call that resolves upon completion.
.factory('currentRestaurantService', ['$rootScope', '$q', function($scope, $q) {
return {
getCurrentRestaurant: function() {
var defer = $q.defer(); // Create a deferring object
$scope.currentUser = Parse.User.current();
// Get restaurant for user
var restaurantObject = Parse.Object.extend("Restaurant");
var query = new Parse.Query(restaurantObject);
var thisUsersRestaurants = query.equalTo("user", $scope.currentUser);
thisUsersRestaurants.find().then(function(restaurants) {
defer.resolve($scope.restaurants);
});
return defer.promise; // Create an Angular promise to be resolved
}
};
}])
I make the call in a resolve block in one of my states hoping to resolve before going to the sales page.
.state('dashboard.sales', {
url: '/sales',
templateUrl: './app/dashboard/partials/sales/sales.html',
controller: 'DashboardSalesCtrl',
resolve: {
currentRestaurant: function() { return currentRestaurantService.getCurrentRestaurant(); }
}
})
I cannot figure out why this doesn't work. I have been banging my head against the wall for the past week and cannot figure it out. What is wrong with my code?
You should inject
currentRestaurantService
dependancy first before using it in resolvecurrentRestaurant
function.Code