Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load images from json file #59

Closed
marioshtika opened this issue Mar 30, 2016 · 5 comments
Closed

Load images from json file #59

marioshtika opened this issue Mar 30, 2016 · 5 comments

Comments

@marioshtika
Copy link

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
Copy link

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
Copy link
Author

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
Copy link

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

@marioshtika
Copy link
Author

You are the best :)

I can't believe it was that simple.

Thank you very much.

@pedroabreu
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants