pedroabreu / ion-gallery

Ionic gallery directive
MIT License
124 stars 61 forks source link

Load images from json file #59

Closed marioshtika closed 8 years ago

marioshtika commented 8 years ago

Hello and congratulation for this great directive.

I want to ask is there a way to load images from a json file and not inside the controller.

If I do so, i think it doesn't load the json file in time to show it.

Can you help me with this?

Thank you in advance.

nabinkumarn commented 8 years ago

You can easily load images from a json file. Make $http call from controller for the json file and assign the result to items.

marioshtika commented 8 years ago

I am doing this: $http.get('gallery.json').then(function (result) { $scope.photos = result.data; console.log($scope.photos); }, function (err) { console.log(err); });

but it still doesn't load them.

The error logs is: "TypeError: Cannot read property 'length' of undefined"

I think the directive doesn't wait for the controller to load the json data.

Is that right? Is there a way to make it work?

nabinkumarn commented 8 years ago

I have faced this issue. Use $scope.photos = [ ] before making the http call

marioshtika commented 8 years ago

You are the best :)

I can't believe it was that simple.

Thank you very much.

pedroabreu commented 8 years ago

This is actually a stupid bug the directive has (and I've been meaning to fix that). You can't pass to the directive an undefined array for items