2016-04-27 18 views
1

内のクッキーを使用ngCookiesProvider <を - ngCookies < - checkLoginService角度: 不明なプロバイダ::私はカスタムサービスで角度クッキーを使用しようとしましたが、エラーましカスタムサービス

は、私は別のファイル内のモジュール、コントローラおよびサービスを保存します。

コントローラー:

(function() { 
    'use strict'; 

    angular 
     .module('app') 
     .controller('AuthController', AuthController); 

    AuthController.$inject = ['$scope', '$http', '$location', 'checkLoginService']; 

    function AuthController($scope, $http, $location, checkLoginService) { 
     /* jshint validthis:true */ 
     var vm = this; 
     vm.title = 'AuthController'; 

     $scope.login = function(user) { 
      /*logic*/ 
     } 

     $scope.checklogin = function() { 
      if (checkLoginService.checkLogin()) { 
       /*logic*/ 
      } 
     } 

     $scope.checklogin(); 
    } 
})(); 

サービス:

(function() { 
    'use strict'; 

    angular 
     .module('app') 
     .service('checkLoginService', ['ngCookies', checkLoginService]); 

    checkLoginService.$inject = ['$http']; 

    function checkLoginService($http, $cookies) { 
     return { 
      checkLogin: function() { 
       /*logic*/ 
      } 
     } 
    } 
})(); 

答えて

1

ngCookiesモジュールではありません依存関係の名前が、あなたはモジュールの依存関係にngCookiesを注入し、クッキーオブジェクトを取得するには$cookiesを使用すべきである

//somewhere in app.js 
angular.module('app', ['otherModules', ..... , 'ngCookies']) 

さらにを追加checkLoginService $ inject配列内の依存関係がありません。

angular.module('app') 
.service('checkLoginService', ['$cookies', checkLoginService]); 
checkLoginService.$inject = ['$http', '$cookies']; 
function checkLoginService($http, $cookies) { 
    return { 
     checkLogin: function() { 
      /*logic*/ 
     } 
    } 
} 
関連する問題