Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

How convert promise to object

$
0
0

@anaider wrote:

Hi,

I am new to ionic and trying to display JSON data from php server with ng-repeat

What I have done so far was to create factory in services.js and controller in controllers.js

Here is my factory

.factory('Items', function($http){
var items = {};
return{
getItems: function(){

  return $http.get("http://myserver.com/myitem.php").then(function(response){
    items = response;
    return items;

And controller

.controller('ItemCtrl', function($scope, Items){

$scope.itemslist = [];
$scope.itemslist = Items.getItems();

})

I tried several different ways to show the itemalist in ng-repeat and it did not work
After creating custom itemlist and testing it in controller ng-repeat was working fine so that it was the problem.

Only I found was that even factory returned object, the controller received as promise, not object. So ng-repeat couldn't display data from promise

Could anyone tell me what I did wrong?

Thanks

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>