2

I am sending data to a Class at parse.com, I would like to run this function and update the $scope without having to reload the view.

To create a Programme running the function below works fine, however it sometimes does not update the view following creating a new programme and it requires a page refresh (when the whole function is called as seen at the bottom - getProgrammes();

getProgrammes = function() {
$ionicLoading.show();

var programmesArray = [];
var QueryProgramme = Parse.Object.extend("Programme");
var query = new Parse.Query(QueryProgramme);

query.equalTo("userId", userId);
query.find({
success: function(results) {
  for(var i=0; i < results.length; i++) {
    var object = results[i];

    var programmeData = { title : object.get('programmeTitle'), 
                          id : object.id,
                          exercises : object.get('exerciseData')
                        };

    programmesArray.push(programmeData);
  }

  $scope.programmes = programmesArray;
  $scope.$apply();
  $ionicLoading.hide();
   },
   error: function(error) {
   alert('You do not have any Programmes - please create one');
   }
 })
};

getProgrammes();

I think I may be hacking this by using $scope.apply() - therefore making it unreliable. Assistance on the correct function to use in order to automatically update $scope would be great.

1
  • You shouldn't need to call $scope.$apply(). You should just be able to set the property on $scope. Perhaps provide a js fiddle demonstrating the problem Commented Jan 18, 2015 at 0:15

1 Answer 1

4

I've been using a library found here:

https://github.com/brandid/parse-angular-patch

Essentially I just reference the parse-angular.js file, and then include the dependency in my app, e.g.:

angular.module('app', [
  'parse-angular',
]);

Then I just use Parse queries anytime I like and they participate correctly with $scope and $apply. The library just does some simple wrapping on the Parse methods to make the async calls obey the rules of angular.

Sign up to request clarification or add additional context in comments.

7 Comments

I've looked at this previously and found I couldn't follow the documentation on it (my lack of experience) however I will look again.
The documentation is overly complicated, that's why I explained it with two simple steps, just add the JS file and add the references to your app declaration, nothing else is needed for basic functionality
I'm being a real dumbass or something, where is the JS file I need? Reference to components/ in index.js but is that some bower magic?
Nope still can't figure out what I should use as the JS file?
Sorry, the simple version I use is found here: github.com/brandid/parse-angular-patch
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.