Keep a variable in session

0

I have on my controller:

app.controller

//ESTO ME DEVUELVE UN LISTADO DE VARIABLES POR EJM
// [ {name:variable1, valor:2}, {name:variable2, valor:5} ]
$scope.variables = TestService.loadVariable()

This is shown in the view and everything is correct, but in the view I can change the name of the first variable to " variablemodificada1 ", if I give f5 it reads " TestService.loadVariable() ", if I already it was called once I do not want it to be called anymore

    
asked by sirdaiz 05.02.2018 в 13:11
source

1 answer

1

If you want these variables to be saved after refreshing the page you should register them in the global browser contexts ( local storage and session storage ). The main difference between them is that local storage will remain active as long as your browser is open and local storage will remain even after closing it.)

To access them and save a variable in AngularJS would be something similar to:

$window.sessionStorage["variable1"] = valor1;
    
answered by 05.02.2018 в 16:00