1

カスタム サービスで角度のある Cookie を使用しようとしましたが、エラーが発生しました: 不明なプロバイダー: 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*/
            }
        }
    }
})();
4

1 に答える 1