模块“'ngFacebook'不可用!”使用ngFacebook服务时出错

时间:2015-04-28 04:52:47

标签: javascript angularjs facebook

您好我正在尝试将facebook与我的角度js网络应用程序集成。为此我在角度js中使用ngFacebook服务。 但是当我执行我的应用程序时,我收到错误

Accounts.config({
    loginExpirationInDays: 900000 //15 minutes this dont work
});

我使用命令“bower install ng-facebook”安装了ngFacebook服务。

这是我的代码

"Uncaught Error: [$injector:modulerr] Failed to instantiate module tveWebApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngFacebook due to:
Error: [$injector:nomod] Module 'ngFacebook' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument".

我的控制器

angular.module('tveWebApp', ['ngFacebook'
    ]).config(['$facebookProvider', function($facebookProvider){

        $facebookProvider.setAppId('709438295835304');
        $facebookProvider.setPermissions("email,user_likes");
        $facebookProvider.setVersion("v2.3");
    }]).run(['$rootScope',
        function($rootScope) {
              (function(){
                 if (document.getElementById('facebook-jssdk')) {return;}
                 var firstScriptElement = document.getElementsByTagName('script')[0];

                 var facebookJS = document.createElement('script'); 
                 facebookJS.id = 'facebook-jssdk';

                 facebookJS.src = '//connect.facebook.net/en_US/all.js';

                 firstScriptElement.parentNode.insertBefore(facebookJS, firstScriptElement);
               }());
}]);

我的观点

  $scope.isLoggedIn = false;
  $scope.login = function() {
    $facebook.login().then(function() {
      refresh();
    });
  }
  function refresh() {
    $facebook.api("/me").then( 
      function(response) {
        $scope.welcomeMsg = "Welcome " + response.name;
        $scope.isLoggedIn = true;
      },
      function(err) {
        $scope.welcomeMsg = "Please log in";
      });
  }

  refresh();

我该如何解决这个问题?提前谢谢。

1 个答案:

答案 0 :(得分:0)

在index.html中添加文件:

<script src="link//to//ng-facebook.js"></script>