1

I am new to mean stack , in fact working on my very first project , i want to remember the request from the specific browser , which i have done using cookies . After that i want to send the history data from the server specific to every request which i am not able to do , as i couldnt find a suitable way . i tried using sessionstorage in angular js but that doesnt pull the session data i kept in node js ) Please let me know how is make it .

Node js: when i have set session var titles here in node js

var chkck = function(req,res,next){
    console.log("inside cookie callback .. ");

req.session.titles = req.session.titles || [];
//titles.push(req.params.)
 req.session.titles.push("22");
    res.sendFile("F:/customer/public/index.html");
}


app.use(chkck);


app.get('/',function(req,res){
res.sendFile("F:/customer/public/index.html");});

angular js: but in angular , i am not able to retrieve the titles from sessionstorage .

var nameapp=angular.module('name-App',["ngRoute",'ngCookies','ngStorage']);
    nameapp.controller('NameCtrl',
        function($scope,$http,$window, $cookieStore,$sessionStorage ){
            $scope.arr=[];
         $scope.finddet=function(){


            console.log("sessionstorage.titles"+ $sessionStorage.titles);
}});

this gives undefined

jayendra bhatt
  • 1,337
  • 2
  • 19
  • 41

1 Answers1

2

In your Nodejs code: convert your response to JSON

res.send(JSON.stringify(data));

Sample answer

AnguarJs:

In your controller file,

$http.get(/your_url).then(function(response){

   // You will get the above response here  in response.data

  })
Community
  • 1
  • 1
ramamoorthy_villi
  • 1,939
  • 1
  • 17
  • 40