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
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
Share Improve this question edited Jan 20, 2015 at 11:00 M.K asked Jan 20, 2015 at 10:48 M.KM.K 2183 silver badges10 bronze badges 2-
Can you show more of your code, ie. where does
data
came from ? – MiTa Commented Jan 20, 2015 at 10:53 - Hi MiTa, I have pasted whole controller, please take a look and if possible suggest me. – M.K Commented Jan 20, 2015 at 11:01
2 Answers
Reset to default 9See 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
I had the same problem. I solved it by adding the prefix "angular." to isObject, isUndefined, isArray and isNumber within the angular-local-storage.js:
angular.isObject, angular.isUndefined ...