luiscarlosjayk/angular-facebook

FacebookProvider.init sometimes fails when you load library through HEAD

mdedetrich opened this issue · 0 comments

Typically, most people load their JS scripts in the head script tag. In regards to angular-facebook, this is a problem specifically in regards to detection of the fb-root element.

The offending issue is in the lines below https://github.com/Ciul/angular-facebook/blob/master/lib/angular-facebook.js#L518-L525

Its possible for document.body to be null, which happens if angular-facebook in the header happens to evaluate before body in the DOM renders.

angular-facebook should be modified so it defers the initialisation of fb-root if the body doesn't happen to exist (yet). This can be done by using the windows.onLoad callback, i.e.

window.onload = function() {
  // Do stuff here
}

This is somewhat related to #36