未知的提供者注入工厂

时间:2014-12-11 11:53:55

标签: angularjs dependency-injection

当我运行我的应用程序时,它总是抛出以下错误:

  

Error: [$injector:unpr] Unknown provider: localStorageServiceProvider <- localStorageService http://errors.angularjs.org/1.3.5/$injector/unpr?p0=localStorageServiceProvider%20%3C-%20localStorageService

这是我的代码: home.js:

   angular.module('home', [])

.controller('homeCtrl', ['$scope', '$location', 'localStorageService',
    function ($scope, $location, localStorageService) {
        $scope.username = "maax",
        $scope.buttonType = "icon ion-search",
        $scope.buttonDisable = false,

        $scope.click = function () {
            $scope.buttonDisable = true
            $scope.buttonType = "icon ion-loading-a"

            //Grap geoLocation        
            var location = navigator.geolocation.getCurrentPosition(sendToServer);

            function sendToServer(pos) {
                //sendGeoData(pos.coords.latitude, pos.coords.longitude, window.localStorage.getItem("userId"))
                savePlayerData("sd");
            }

            //Ask server for availalble player an get data

            //End server request


            //Link to play-screen
            $location.path("/tab/play-screen");
            localStorageService.addEvent();
        };

}])

这是我的服务,我尝试注入:

'use strict'
angular.module('service', [])

//var testEvent = {
//    "playerName": "Max",
//    "aufgabe": "Döner kaufen"
//}
//
//localStorage.setItem('events', testEvent);
//Create a hitsotry of Events to see the recent Events

.factory('localStorageService', function () {
    return {
        addEvent: function () {
            return null
        }
    }
    //
    //    return 1;
    //    //Pull the current events
    //    var event = JSON.parse(localStorage.getItem('events'));
    //
    //    /*overwrite the localStorage with the newest Event added in 
    //            the begining */
    //
    //    var eventUpdatet = newEvent;
    //    eventUpdatet.push(events);
    //    localStorage.setItem('events', JSON.stringify(eventUpdated));

});

我希望你能帮助我,因为我真的没有看到我的错误。 非常感谢!!

1 个答案:

答案 0 :(得分:0)

您需要插入两个模块的依赖关系,修复此行:

angular.module('home', ['service'])