1

I am stuck at hiding and showing login/logout buttons at navbar. I am setting some cookies at loginCtrl belongs to login.html. And getting those cookies in homeCtrl which belongs to home.html. Here is my code;

.controller("loginCtrl", function($scope, $rootScope, $cookies, $state) {
    $scope.login = function () {
         Auth.$authWithPassword({}).then(function() {

             $rootScope.bekmez = true; // Using this in home.html > navbar.
             $cookies.put('Some', true);
             $state.go('baba.ana.manga');
})
.controller("homeCtrl", function($scope, $cookies) {

         $scope.bekmez = $cookies.get("Some");
)}

My navbar:

<li ng-show="bekmez">Username</li>
<li ng-hide="bekmez">Login Button</li>

So i did some googling and find that;

Cookies are only added to the browser on digest.

I dont know what the digest is. So what is the possible solution to my problem?

Nasuh
  • 355
  • 3
  • 20
  • I am sorry, but what is yours problem? You didn't mention it. Regarding code it looks ok. Everything what you can do with cookies(settings) is : https://docs.angularjs.org/api/ngCookies/provider/$cookiesProvider – Errorpro Nov 05 '15 at 02:56
  • @Errorpo Problem is when i logged in login button stil shows up but when i refresh the page login button is gone. So cookie is in place no problem there but problem occur because of saving the cookies happening after the `$rootScope.bekmez = true`. – Nasuh Nov 05 '15 at 03:04

0 Answers0