Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用angularjs在html页面中检索nodejs会话值?_Angularjs_Node.js_Express Session - Fatal编程技术网

如何使用angularjs在html页面中检索nodejs会话值?

如何使用angularjs在html页面中检索nodejs会话值?,angularjs,node.js,express-session,Angularjs,Node.js,Express Session,我正在使用expresssession在nodejs中创建会话&使用http.post方法向nodejs发送数据。如何使用angularjs检索html中的会话变量?你能帮帮我吗 这是我的密码 在第一个html页面的angularjs控制器内 $http.post('/form', data) .then( function(response){ if (response.data) {

我正在使用expresssession在nodejs中创建会话&使用http.post方法向nodejs发送数据。如何使用angularjs检索html中的会话变量?你能帮帮我吗

这是我的密码

在第一个html页面的angularjs控制器内

   $http.post('/form', data)
       .then(
           function(response){
               if (response.data) {
                   $window.location.href = 'other.html'; 
                }
           }, 
           function(response){
               console.log("inside failure");
           }
        );
在nodejs中

         app.post('/form', function (req, res) {
           console.log("Incoming data" , userData);
           req.session.mob = userData.mob;
           req.session.provider = userData.provider;
           res.send(req.session.mob);
         }
             

我必须在nodejs会话中存储的'other.html'中显示mob值。您能建议我如何通过angularjs执行此操作吗?

不确定我是否正确理解您的问题-我会尽力帮助您。 首先,angularJs的最佳实践是使用路由或状态,并将从服务器接收的数据(在您的示例中为response.data)作为状态参数或url参数传递到新页面,并避免重定向。 如果确实需要重定向到“other.html”,只需将数据作为url中的查询参数从服务器传递(如果是属性)或将其保存在浏览器存储区(如果在新选项卡中打开新页面,则保存在本地存储区)中,并在加载other.html时读取数据

确保将url传递到$window.location.href