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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With