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

slow connection: Cannot read property '0' of undefined (scope.newFilm = scope.films[0]) #8

Open
jmp909 opened this issue Dec 13, 2015 · 1 comment

Comments

@jmp909
Copy link

jmp909 commented Dec 13, 2015

on your code from video 33 (https://www.youtube.com/watch?v=Ob9E1-TFUBs) , if i throttle Chrome to 2G (450kb/s), an error gets thrown from nextfilm.directive.js

TypeError: Cannot read property '0' of undefined
scope.newFilm = scope.films[0];

presumably then, this hasn't run from upcomingfilms.controller.js
$scope.films = allMovies;

is this an inherent issue to Angular? i wasn't sure why you have a 300ms timeout on functions. I assume it's related to everything running correctly in order.

is there a way to make one dependent on the other to avoid this error?

i console logged the various functions and it comes out like in this order, presumably meaning the nextfilm 300ms timeout is firing before the promise completes

MCU.directive.maincontent
MCU.directive.maincontent.link
MCU.directive:nextfilm
MCU.service:phasesService
MCU.controller:upcomingfilmsController
MCU.service:phasesService.getPhases
MCU.directive:nextfilm.link
MCU.directive.maincontent.link.timeout
MCU.directive:nextfilm.link.timeout   // allMovies not set yet so errors...

TypeError: Cannot read property '0' of undefined

MCU.service:phasesService.getJson->deferred resolve
MCU.controller:upcomingfilmsController.promise.then
MCU.controller:upcomingfilmsController.allMovies

thanks
j

@jmp909
Copy link
Author

jmp909 commented Dec 13, 2015

rather than put a timeout in the link function, this seems to work as an alternative to avoid the error

var unwatch = scope.$watch('films', function() {
    if(scope.films && scope.films[0]) {
        scope.newFilm = scope.films[0];
        unwatch();
    }
})

I'm pretty new to angular, so I'm not sure if this is the best approach

thanks
j

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

1 participant