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










share|improve this question


























    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










    share|improve this question
























      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










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 14:56









      ⵍⵢⴻⵙ

      529




      529
























          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)





          share|improve this answer























          • that works thank you
            – ⵍⵢⴻⵙ
            Nov 11 at 16:02











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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)





          share|improve this answer























          • that works thank you
            – ⵍⵢⴻⵙ
            Nov 11 at 16:02















          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)





          share|improve this answer























          • that works thank you
            – ⵍⵢⴻⵙ
            Nov 11 at 16:02













          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)





          share|improve this answer














          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)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues