Including Angular localStorageService in module causes native error

135 Views Asked by At

This code works; the getData() function is invoked:

    var app = angular.module('POC', []);
    app.controller('POCCtrl', ['$scope','$timeout', function ($scope, $timeout) {

         <snip>

        $timeout(function () {
            $scope.getData()
        }, 250, $scope);

    ]);

But the code below , which references localStorageService, causes a native error in IE when I try to run and debug the page. The getData() function is never invoked. What am I missing? Does the local storage service have to be included in the module too?

       var app = angular.module('POC', []);
        app.controller('POCCtrl', ['$scope','$timeout', 'localStorageService', 
           function ($scope, $timeout, localStorageService) {

            $timeout(function () {
                $scope.getData()
            }, 250, $scope);

        ]);
1

There are 1 best solutions below

0
Himanshu On

use

app.controller('POCCtrl', 
       function ($scope, $timeout, localStorageService) {

);

I don't know why but the controller just doesn't take localStorageService in the way you are using, I had the same error today. See my question (I am myself looking for an explanation though)

Error in angular-js while using angular-local-storage