Angularjs Facebook Login: Cannot read property 'appendChild' of null

喜欢而已 提交于 2020-01-03 06:36:09

问题


I am using angular-facebook module for adding Facebook Login capability to my application.

Generally I get the following error while loading the page:

The "fb-root" div has not been created, auto-creating Cannot read property 'appendChild' of null

When I get this error the facebook login popup comes empty/blank or unable to login.

My angular module dependencies are below:

angular.module('myApp', ['ngResource', 'ngRoute', 'facebook', 'restangular', 'LocalStorageModule'])

My index.html:

<html>
  <head>
    ..
    ..
     <script src="index.js"></script>
    <script src="assets/js/default.js"></script>
</head>
<body ng-view>
</body>

</html>

回答1:


The problem occurs because of ng-view tag in <body> ngRoute organizes the content of body itself but facebook js sdk tries to control 'fb-root' div under body.

The solution is to move ng-view to an inner div under body and create a fb-root div optionally:

<html>
  <head>
     <script src="index.js"></script>
    <script src="assets/js/default.js"></script>
</head>
  <body>
  <div id="fb-root"></div>
  <div ng-view>
  </div>
</body>
</html>


来源:https://stackoverflow.com/questions/28404996/angularjs-facebook-login-cannot-read-property-appendchild-of-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!