3

I am working with angularjs and I am trying to access a value stored in vm.userid to the server side. I want to store a value from session-storage to vm.userid and then send it with the API request. I have checked my session-storage and the value I seek is indeed there. My value doesn't show up on the server-side, but a couple of minutes later it comes back empty (userid: " ").

This is the function in the StatisticsController:

(function () {
'use strict';
angular
.module('app')
.controller('StatistikController', StatistikController);

StatistikController.$inject = ['$location', 'AdminService','FlashService'];
function StatistikController($location, AdminService, FlashService) {
var vm = this;

vm.logout = logout;

initController();

function initController() {
    loadStat();
}

function loadStat() {
        vm.userid = angular.fromJson(sessionStorage.getItem('userid'));
        AdminService.Stat(vm.userid)
            .then(function (allStats) {
                vm.allStats = allStats;
            });
    }   

This is were the userid item is set to sessionStorage (which is in a different controller):

function loadUserid() {
    UserService.GetUserid($rootScope.globals.currentUser.username)
        .then(function (userid) {
            vm.userid = userid;
            sessionStorage.setItem('userid', angular.toJson(vm.userid));
        });
}
Ann
  • 49
  • 3

0 Answers0