0

I use parse.com SDK in my AngularJS application with this code in a controller:

var MyData= Parse.Object.extend('MyData');
var query = new Parse.Query(MyData);

query.find({
    success: function(results) {
        $scope.$apply(function() {
            $scope.resultData = results.map(function(obj) {
                return createMyDataObjectFromParseObject(obj);
            });
        });
    }
});

function createMyDataObjectFromParseObject(parseObject){
    return {
        startDate: parseObject.get('StartDate'),
        endDate: parseObject.get('EndDate'),
        investment: parseObject.get('Investment'),
        format: parseObject.get('Format'),
        partner: parseObject.get('Partner'),
        purpose: parseObject.get('Purpose')

    };
}

Now I would like to use the content stored in $scope.resultData inside another function but whenever I call it outside the query.find() function it's undefined... Why is this and how can I make it store the data in a scope for later use? New to Angular so bear with me please. Thank's!

David
  • 1,171
  • 8
  • 26
  • 48

1 Answers1

0

You need to put that code inside a Service Module, more especifically the service() method of angular, the Stackoverflow link below especify how and when to use the diferent service modules.

AngularJS: Service vs provider vs factory

Community
  • 1
  • 1