can't inject ngStorage into my controller
up vote
0
down vote
favorite
hi i'm trying to inject ngtorage to handle sessions locally, i tried different ways to do it but without results:
here is my app.js
var myApp = angular.module('myApp', ['ngStorage']);
loginController.js in a separated file:
myApp.controller('logincontroller', ['$scope', '$http','log', function($scope, $http ,log,$sessionStorage)
{
$scope.auth = function(){
log.logIn($scope.pseudo,$scope.pwd).
then(function(data){
if (data.data.log == true){
$scope.logged = true;
$scope.success = "Hey ! t'es connect";
$sessionStorage.user = data.data.pseudo;
}else
{
$scope.erreur = "connexion echouée";
$scope.error = true;
}
});
}
}]);
and authSerivce.js the service that i'm injecting into my controller
angular.module('myApp').factory('log', ['$http', function($http){
return{
/*Check whether the user is logged in
* @returns boolean
*/
isLoggedIn: function isLoggedIn(){
return session.getUser() !== null;
},
/*Log in
* @param credentials
* @returns {*|Promise}
*/
logIn: function(username, pwd){
return $http
.post('/login', {'username':
username, 'pwd': pwd})
.success(function(data){
if (data.log == true){
console.log(data);
//$localstorage.user= data.pseudo;
return data;
}
}).error(function(data){
return data;
});
},
/* Log out : on peut se poser la question d'une requête HTTP ! pour faire le
ménage côté serveur ?!
* @returns {*|Promise}
*/
logOut: function(){
return $http
.get('/logout')
.then(function(response){
// Destroy session in the browser
session.destroy();
return(response.data);
});
}
}
}]);
the line returning error is
$sessionStorage.user = data.data.pseudo;
the error is Cannot set property 'user' of undefined
help much appreciated guys
angularjs ng-storage
add a comment |
up vote
0
down vote
favorite
hi i'm trying to inject ngtorage to handle sessions locally, i tried different ways to do it but without results:
here is my app.js
var myApp = angular.module('myApp', ['ngStorage']);
loginController.js in a separated file:
myApp.controller('logincontroller', ['$scope', '$http','log', function($scope, $http ,log,$sessionStorage)
{
$scope.auth = function(){
log.logIn($scope.pseudo,$scope.pwd).
then(function(data){
if (data.data.log == true){
$scope.logged = true;
$scope.success = "Hey ! t'es connect";
$sessionStorage.user = data.data.pseudo;
}else
{
$scope.erreur = "connexion echouée";
$scope.error = true;
}
});
}
}]);
and authSerivce.js the service that i'm injecting into my controller
angular.module('myApp').factory('log', ['$http', function($http){
return{
/*Check whether the user is logged in
* @returns boolean
*/
isLoggedIn: function isLoggedIn(){
return session.getUser() !== null;
},
/*Log in
* @param credentials
* @returns {*|Promise}
*/
logIn: function(username, pwd){
return $http
.post('/login', {'username':
username, 'pwd': pwd})
.success(function(data){
if (data.log == true){
console.log(data);
//$localstorage.user= data.pseudo;
return data;
}
}).error(function(data){
return data;
});
},
/* Log out : on peut se poser la question d'une requête HTTP ! pour faire le
ménage côté serveur ?!
* @returns {*|Promise}
*/
logOut: function(){
return $http
.get('/logout')
.then(function(response){
// Destroy session in the browser
session.destroy();
return(response.data);
});
}
}
}]);
the line returning error is
$sessionStorage.user = data.data.pseudo;
the error is Cannot set property 'user' of undefined
help much appreciated guys
angularjs ng-storage
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
hi i'm trying to inject ngtorage to handle sessions locally, i tried different ways to do it but without results:
here is my app.js
var myApp = angular.module('myApp', ['ngStorage']);
loginController.js in a separated file:
myApp.controller('logincontroller', ['$scope', '$http','log', function($scope, $http ,log,$sessionStorage)
{
$scope.auth = function(){
log.logIn($scope.pseudo,$scope.pwd).
then(function(data){
if (data.data.log == true){
$scope.logged = true;
$scope.success = "Hey ! t'es connect";
$sessionStorage.user = data.data.pseudo;
}else
{
$scope.erreur = "connexion echouée";
$scope.error = true;
}
});
}
}]);
and authSerivce.js the service that i'm injecting into my controller
angular.module('myApp').factory('log', ['$http', function($http){
return{
/*Check whether the user is logged in
* @returns boolean
*/
isLoggedIn: function isLoggedIn(){
return session.getUser() !== null;
},
/*Log in
* @param credentials
* @returns {*|Promise}
*/
logIn: function(username, pwd){
return $http
.post('/login', {'username':
username, 'pwd': pwd})
.success(function(data){
if (data.log == true){
console.log(data);
//$localstorage.user= data.pseudo;
return data;
}
}).error(function(data){
return data;
});
},
/* Log out : on peut se poser la question d'une requête HTTP ! pour faire le
ménage côté serveur ?!
* @returns {*|Promise}
*/
logOut: function(){
return $http
.get('/logout')
.then(function(response){
// Destroy session in the browser
session.destroy();
return(response.data);
});
}
}
}]);
the line returning error is
$sessionStorage.user = data.data.pseudo;
the error is Cannot set property 'user' of undefined
help much appreciated guys
angularjs ng-storage
hi i'm trying to inject ngtorage to handle sessions locally, i tried different ways to do it but without results:
here is my app.js
var myApp = angular.module('myApp', ['ngStorage']);
loginController.js in a separated file:
myApp.controller('logincontroller', ['$scope', '$http','log', function($scope, $http ,log,$sessionStorage)
{
$scope.auth = function(){
log.logIn($scope.pseudo,$scope.pwd).
then(function(data){
if (data.data.log == true){
$scope.logged = true;
$scope.success = "Hey ! t'es connect";
$sessionStorage.user = data.data.pseudo;
}else
{
$scope.erreur = "connexion echouée";
$scope.error = true;
}
});
}
}]);
and authSerivce.js the service that i'm injecting into my controller
angular.module('myApp').factory('log', ['$http', function($http){
return{
/*Check whether the user is logged in
* @returns boolean
*/
isLoggedIn: function isLoggedIn(){
return session.getUser() !== null;
},
/*Log in
* @param credentials
* @returns {*|Promise}
*/
logIn: function(username, pwd){
return $http
.post('/login', {'username':
username, 'pwd': pwd})
.success(function(data){
if (data.log == true){
console.log(data);
//$localstorage.user= data.pseudo;
return data;
}
}).error(function(data){
return data;
});
},
/* Log out : on peut se poser la question d'une requête HTTP ! pour faire le
ménage côté serveur ?!
* @returns {*|Promise}
*/
logOut: function(){
return $http
.get('/logout')
.then(function(response){
// Destroy session in the browser
session.destroy();
return(response.data);
});
}
}
}]);
the line returning error is
$sessionStorage.user = data.data.pseudo;
the error is Cannot set property 'user' of undefined
help much appreciated guys
angularjs ng-storage
angularjs ng-storage
asked Nov 11 at 14:56
ⵍⵢⴻⵙ
529
529
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You are missing $sessionStorage
in the order of parameters , change it as follows
myApp.controller('logincontroller', ['$scope', '$http','log','$sessionStorage',
function($scope, $http ,log,$sessionStorage)
that works thank you
– ⵍⵢⴻⵙ
Nov 11 at 16:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You are missing $sessionStorage
in the order of parameters , change it as follows
myApp.controller('logincontroller', ['$scope', '$http','log','$sessionStorage',
function($scope, $http ,log,$sessionStorage)
that works thank you
– ⵍⵢⴻⵙ
Nov 11 at 16:02
add a comment |
up vote
0
down vote
accepted
You are missing $sessionStorage
in the order of parameters , change it as follows
myApp.controller('logincontroller', ['$scope', '$http','log','$sessionStorage',
function($scope, $http ,log,$sessionStorage)
that works thank you
– ⵍⵢⴻⵙ
Nov 11 at 16:02
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You are missing $sessionStorage
in the order of parameters , change it as follows
myApp.controller('logincontroller', ['$scope', '$http','log','$sessionStorage',
function($scope, $http ,log,$sessionStorage)
You are missing $sessionStorage
in the order of parameters , change it as follows
myApp.controller('logincontroller', ['$scope', '$http','log','$sessionStorage',
function($scope, $http ,log,$sessionStorage)
edited Nov 11 at 15:40
Pankaj Parkar
111k15158233
111k15158233
answered Nov 11 at 15:29
Sajeetharan
115k27157215
115k27157215
that works thank you
– ⵍⵢⴻⵙ
Nov 11 at 16:02
add a comment |
that works thank you
– ⵍⵢⴻⵙ
Nov 11 at 16:02
that works thank you
– ⵍⵢⴻⵙ
Nov 11 at 16:02
that works thank you
– ⵍⵢⴻⵙ
Nov 11 at 16:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249941%2fcant-inject-ngstorage-into-my-controller%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown