dongtui4038 2016-11-15 13:02
浏览 63
已采纳

将json值存储为angular中的会话

I have a php file which returns json result based from a $http post as seen here:

json result:

now, in my controller below, i want to store 03-1314-00916 or data[0]['student_number'] as a session in angular so i can use it anywhere in any of my controllers. How will i make it.

app.controller('signInCtrl', function($scope, $stateParams, $http) {
  $scope.txtUsername = '';
  $scope.txtPassword = '';

  $scope.signIn = function(){
    $http.post('http://infoyon_login.php',
      {'username' : this.txtUsername, 'password': this.txtPassword})
    .success(function(data){
      if(data[0]['logged'] === true)
      {
        $scope.unable = false;
        console.log(data[0]);
        console.log(data[0]['student_number']);
  here --> someSessionVar = data[0]['student_number'];      
        //window.location = '#/app/dashboard';
      }else{
        //console.log('unable to login');
        $scope.unable = true;

      }
      //console.log(data[0]['logged']);
    })
  }
}) //end controller

</div>
  • 写回答

2条回答 默认 最新

  • duanli3277 2016-11-15 13:06
    关注

    Use HTML5 sessionStorage

    if(data[0]['logged'] === true)
      {
        $scope.unable = false;
        console.log(data[0]);
        console.log(data[0]['student_number']);
        sessionStorage.setItem('student_number', data[0]['student_number']);      
        //window.location = '#/app/dashboard';
      }
    

    To retrieve

       $scope.studentNumber = sessionStorage.getItem('student_number');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥30 itest不允许查看成绩怎么办
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏