Update Data Binding in NavBar after logging in

1

I have navbar which is included in the index.html page

<body>
       <div class="container">
         <div ng-controller="colaboradorController" ng-include="'public/views/navBar.html'"></div>
         <div ng-view></div>
      </div>

      </div>
</body>

So far so good, in this navBar I have a Data Binding where I get the logged in user:

<p class="navbar-text usuarioLogado">{{usuarioLogado}}</p>

The controller that is being used is the contributorController, in this controller I have a function that takes the user logged in:

var init = function () {
        var temp = sessionStorage.getItem('userLogado');
        var viewName = $.parseJSON(temp); 

        if(viewName != null){
            $scope.usuarioLogado = viewName.usuario.nome;
        }else{
            $scope.usuarioLogado = "";
        }
    };

And start this function when the page opens:

init();

The problem is that when the page is opened usuarioLogado is not displayed in NavBar , it only appears after F5 . I already made a console.log to see if it is being loaded along with the page and it is loaded. I'm just not able to instantly update this Navbar being included in my index.html .

How do I solve this problem?

    
asked by anonymous 30.09.2015 / 16:36

1 answer

0

Getting the sessionStorage information might be a good one, but in that case how the state of the variable is changeable would be nice if you put a watch to observe each event if the value remains the same.

Take a look at this link: ( link ), explains quickly as the watch and the digest cycle work.

SessionStorage is good for saving service queries, but for things that have a defined return, which does not change. This may help to clarify some more. ( link )

    
01.10.2015 / 02:23