在我的AngularJs应用程序中,我试图使用localStorage服务,我引用了“angular-local-storage.js”并将服务注入(inject)到模块中

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

当我尝试在我的 Controller 中使用服务时,它会抛出错误。
(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;
}]);

}());

引发错误:

ReferenceError:isUndefined未定义

任何建议都是高度推荐的。

提前致谢

最佳答案

参见github issue here

简而言之,您可能是在其主页上引用了该版本,该页面的顶部没有包含该行



解决方案是使用github中的版本,或者最好使用bower安装

关于javascript - localStorageService.set返回 "isUndefined is not defined",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28043411/

10-11 12:50