Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorageService.set returns "isUndefined is not defined"

In my AngularJs application i am trying to use localStorage service, I have made reference of "angular-local-storage.js" and injected service in to module

var app = angular.module('SampleApp', ['ngRoute', 'ngSanitize', 'toaster', 'LocalStorageModule']);

When I am trying to consume service in my one of controller its throwing error.

(function () {

var app = angular.module('SampleApp');

app.controller('loginController',  ['$scope', 'notificationFactory', '$location', 'HTMLEditorService', '$rootScope', '$q', 'localStorageService',
function ($scope, notificationFactory, $location, HTMLEditorService, $rootScope, $q, localStorageService) {

    var _authentication = {
        isAuth: false,
        userName: ""
    };

    $scope.bind = function (data) {
        if (data.status) {
            if (data.Metadata.ErrorMessage == null || data.Metadata.ErrorMessage.trim() == '') {

                if (data.Metadata.AuthToken == null || data.Metadata.AuthToken.trim() == '') {
                    notificationFactory.error("User authentication failed. Please try again.");
                }
                else {
                    var deferred = $q.defer();
                    localStorageService.set('authorizationData', {  userName: data.Data.UserName });

                    _authentication.isAuth = true;
                    _authentication.userName = data.Data.userName;

                    deferred.resolve(response);

                    notificationFactory.success('User logged-in successfully!');
                    $rootScope.isLoggedIn = true;
                    $location.url('/LandingPage');
                }
            }
            else {
                notificationFactory.error(data.Metadata.ErrorMessage);
            }
        } else {
            notificationFactory.error('Server Error. Please try again.');
        }
    }

    $scope.userLogin = function () {
        try {

            if (loginValidation(this.userName, this.password)) {

                var request = new Object();
                request.Metadata = new Object();
                request.Data = new Object();

                request.Metadata.SecurityGroupId = 1;

                request.Data.UserName = this.userName;
                request.Data.Password = this.password;

                HTMLEditorService.userLogin(request)
                    .then($scope.bind);
            }
            else {
                notificationFactory.error('Invalid credentials');
            }
        } catch (e) {
            notificationFactory.error('Error! Please try again.');
            console.log(e);
        }
    }


    $scope.cancelLogin = function () {
        try {
            this.userName = '';
            this.password = '';

            $location.url("/Login");
        } catch (e) {
            notificationFactory.error('Error! Please try again.');
        }
    }
    $rootScope.isLoggedIn = false;
}]);

}());

Error Thrown:

ReferenceError: isUndefined is not defined

Any suggestion is highly appriciated.

Thanks in advance

like image 558
M.K Avatar asked Jan 20 '15 10:01

M.K


1 Answers

See github issue here.

In short, you're probably referencing the version from their home page, which doesn't include the line at the top

var isDefined = angular.isDefined

The solution is to use the version from github or, preferably, install using bower

bower install angular-local-storage --save

like image 69
Taran Avatar answered Nov 04 '22 14:11

Taran