Update page without losing the value of a variable

Asked

Viewed 1,423 times

0

I have a vector that receives data coming from a socket that I use for user notifications, but every time I change pages I lose all the value coming from this variable, I’m using angular on the front end. How do I make it so that I can navigate normally in the system without losing the values within my vector? PS: If anyone knows any logic, tutorial related to angular and notifications (facebbok style, twitter, etc), can pass me that I will study. Thank you

  • http://php.net/manual/en/function.session-start.php an option...

2 answers

1


You can create a service and store in it, because when the page is updated the service is not restarted.

    angular.module('app', [''])
  .service('myService', myService);

  function myService($http) {
    var dados;

    function setDados(valor) {
      dados = valor;
    }

    function getDados() {
      return dados
    }

  }

After that just inject the service into your controller and access the functions

angular.module('heroApp', [])
  .controller('myCtrl', myCtrl)

  function myCtrl($scope, myService) {
    var contato = {
      email:'[email protected]',
      nome:'Fulano'
    }

    myService.setDados(contato);

    console.log(myService.getDados())

  }

0

This example illustrates the basic creation of a session anchored in a global variable. However the exaggerated use of global variables brings serious risks application. The above comments a colleague indicates a study material of $_SESSION I suggest you study this before implementing. Also this Link. I hope I helped good study.

      <?php
      session_start();

      $st=mysqli_query($conn,"select * from usuarios where login='$doc'");
      $result=mysqli_fetch_array($st);

      $_SESSION['usuario'] = $result['nome'];
  ?>
<html>
 <head>
</head>
<body>
    <?php
    if ($_SESSION['usuario'] === false){
      Session_destroy();
      header("location: index"); exit;
    }
        <li class="dropdown">
            <a href="" class="dropdown-toggle" data-toggle="dropdown"><?php  echo $_SESSION['usuario'] ?> <span class="caret"></span></a>
                <ul class="dropdown-menu">
                <li><a href="editarperfil">Editar</a></li>
                <li><a href="logout">Sair</a></li>
            </ul>
        </li>
    </ul>
    ?>
</body>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.