Nella mia applicazione AngularJs sto cercando di utilizzare il servizio localStorage, ho fatto riferimento di "angolare-local-storage.js" e iniettato servizio al modulolocalStorageService.set restituisce "isUndefined non è definito"
var app = angular.module('SampleApp', ['ngRoute', 'ngSanitize', 'toaster', 'LocalStorageModule']);
Quando sto cercando di consumare il servizio nel mio controller, il suo errore di lancio.
(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;
}]);
}());
errore generato:
ReferenceError: isUndefined non è definito
Ogni suggerimento è altamente appriciated.
Grazie in anticipo
Puoi mostrare altro codice, es. da dove proviene 'data'? – MiTa
Ciao MiTa, ho incollato l'intero controller, si prega di dare un'occhiata e se possibile suggerirmi. –