Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have a controller that, through Parse, successfully retrieves and pushes an object onto an array as so:

var mySite = angular.module('mySite', []);

mySite.controller('listConnectors', ['$scope',
    function ($scope) {
        //Parse.initialize here;
        $scope.array = [];
        var TestObject = Parse.Object.extend("TestObject");
        var query = new Parse.Query(TestObject);
        query.find({
            success: function (results) {
                alert("Successfully retrieved " + results.length + " rows.");
                // Do something with the returned Parse.Object values
                for (var i = 0; i < results.length; i++) {
                    var object = results[i];
                    alert(object.id + ' - ' + object.get('foo') + " " + object.get('num'));

                    /***** Pushing onto array here *******/
                    $scope.array.push(object);

                }

                console.log($scope.array[0].attributes.foo); //Grabbed what was needed

            },
            error: function (error) {
                alert("Error: " + error.code + " " + error.message);
            }
        });
}]);

I am then, unsuccessfully, trying to loop and list the "foo" value of every object in the array, as the console.log above shows. However, nothing is outputted. It's as though, possibly, the ng-repeat is not being executed or entered:

    <li ng-repeat="eachElement in array">
    <a > {{eachElement.attributes.foo}}</a>
    </li>

Any help would be appreciated. Thanks!

share|improve this question
    
    
have you tried $apply ? – webduvet Nov 20 '14 at 22:56

The code in your alert statement and inside the ng-repeat directive do not match. Your alert accesses "x.id" whereas your dom binding accesses "x.attributes.id".

If your alert is showing the expected result, you should change the HTML as follows:

<li ng-repeat="eachElement in array">
<a > {{eachElement.id}}</a>
</li>
share|improve this answer
    
My 'console.log($scope.array[0].attributes.foo); //Grabbed what was needed' is what I would like to be displayed, I should have removed the alert because it uses Parse methods. Please pay no attention to it. But either way, {{eachElement.id}} doesn't output anything either. – StackPWRequirmentsAreCrazy Nov 21 '14 at 14:51
    
I had meant to put eachElement.attributes.foo, but that doesn't work either. Sorry about the confusion. – StackPWRequirmentsAreCrazy Nov 21 '14 at 14:57
    
Did you try {{eachElement.attributes.foo}} to see if that worked? I know it's not the property you are looking for. EDIT: beat me to it. – James Talmage Nov 21 '14 at 14:58
    
Yeah, nothing is outputted either :(. – StackPWRequirmentsAreCrazy Nov 21 '14 at 14:59
1  
Let us continue this discussion in chat. – James Talmage Nov 21 '14 at 15:02
up vote 1 down vote accepted

I was able to fix it. Thank you Jonathan Lonowski for the comment and link.

I had to wrap the push onto array with an $apply:

$scope.$apply(function(){
  $scope.array.push(object);
});
share|improve this answer
    
It is very helpful. – Monika Apr 27 '15 at 10:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.