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

how to resolve a error Cannot read property '0' of undefined #39

Open
ghost opened this issue Apr 28, 2016 · 2 comments
Open

how to resolve a error Cannot read property '0' of undefined #39

ghost opened this issue Apr 28, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 28, 2016

GalleryCtrl.js :
angular.module('myApp').controller('GalleryCtrl',[function($scope,$document){
var self = this;

self.images = [
    {thumb: 'image/slider/1.jpg', img: 'image/slider/1.jpg', description: 'Image 1'},
    {thumb: 'image/slider/2.jpg', img: 'image/slider/2.jpg', description: 'Image 2'},
    {thumb: 'image/slider/3.jpg', img: 'image/slider/3.jpg', description: 'Image 3'},
    {thumb: 'image/slider/4.jpg', img: 'image/slider/4.jpg', description: 'Image 4'}
];

}]);

Gallery.html :

and i add 'jkuri.gallery' in app.js file but i have e error :

TypeError: Cannot read property '0' of undefined
at Scope.scope.getImageDownloadSrc (ngGallery.js:129)
at fn (eval at (angular.js:14138), :4:248)
at expressionInputWatch (angular.js:15191)
at Scope.$digest (angular.js:16730)
at Scope.$apply (angular.js:17003)
at done (angular.js:11324)
at completeRequest (angular.js:11522)
at XMLHttpRequest.requestLoaded (angular.js:11463)

please help me

@tomchinery
Copy link

tomchinery commented Apr 29, 2016

I had the same issue in a Ruby on Rails application where I needed to use ngGallery. I was using Restangular to set an empty array of images then update it when the promise resolved. My solution was to use an ng-if in the view:

<ng-gallery images="ctrl.images" ng-if="ctrl.images.length"></ng-gallery>

Let me know if that works,

@prcbass
Copy link

prcbass commented May 23, 2016

@tomchinery This worked well. Thanks!

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

2 participants