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.
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]);
After the for loop have you try to print in the console $scope.items?
console.log($scope.items);