0

I am using Ionic Framework for my PhoneGap/Cordova project. I am having some issues in updating the view from the controller.

This is the view I am using.

<ion-view view-title="Designs">
    <ion-content class="padding">
        <p>{{items.url}}</p>
        <p>{{items.notes}}</p>
    </ion-content>
</ion-view>

Below is my controller code. I am getting some data from remote cloud server and it can have 0 or more data at any given point of time. I want these values to be captured and shown in the above view template.

Basically I understand that it needs to be put in an array. I am not sure how that array can be parsed in the view in a loop.

app.controller('ViewCtrl', function($rootScope, $scope, $ionicPopup, $ionicLoading) {

    var query = some-remote-data-source();

    query.find({
        success: function(results) {

            for (var i = 0; i < results.length; i++) {
                    // How to assign the values which can be displayed in the view?
                    $scope.items = results[i].url();
            }

        },
        error: function(e) {

        }
    });
});

Kindly let me know if I have missed any data that might help to answer this.

2
  • Is the $scope.items just empty in your frontend? Is the array populated (chrome inspector)? Commented Jan 26, 2015 at 18:48
  • Hi, i am looking to know the best way to populate the array in ionic. Commented Jan 26, 2015 at 18:51

2 Answers 2

1

My personal favourite: This find() function is communicating with a webservice? Maybe written in PHP? Most of the webservices are returning the data in JSON format. So the only thing you have to do in your controller is:

$scope.items = response; 

So what you need to do is: Edit your webservice so it´s returning JSON formatted data.

If you´re not using a webservice you can populate your array the angular way (do this in your loop):

$scope.items.push(items[i]);
Sign up to request clarification or add additional context in comments.

Comments

0

After the for loop have you try to print in the console $scope.items?

console.log($scope.items);

Comments

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.