2

I am having a situation here, my website is built with angularjs. My entire routes are managed through angular. After my successful login, I redirect user to dashboard page. I have a show hide condition on an element, which stopped working now. Here's the code:

<div id="TilesController" ng-show="ShowTiles" ng-controller="TilesController">
                <div class="" id="tiles" ng-include src="'tiles.html'"></div>
            </div>

So tiles are only visible to loggedin users. After login, tiles should be visible, I listen to routechangesuccess event and change it according, but its not working.

$scope.$on('$routeChangeSuccess', function(event, next, current) {
    if(userLoggedIn !== undefined){
        $scope.ShowTiles = true;
    }
});

But this is not enabling the tile, though if I console.log($scope.ShowTiles); it shows true. I tried safeapply, but still not helping, but if I refresh the entire page, then it works.

jaybutani
  • 189
  • 1
  • 12

1 Answers1

0

What about adding the ng-show directive inside the controller scope? At this point i am not sure if you are updating the userLoggedIn variable, you maybe want to attach it to the $scope.

  <div id="TilesController" ng-controller="TilesController">
                    <div ng-show="ShowTiles" id="tiles" ng-include src="'tiles.html'"></div>
                </div>
Raulucco
  • 3,406
  • 1
  • 21
  • 27
  • Did you bind the userLoggedIn to the $scope? Besides the event is tight to the routeChangeSuccess, so to fired it have to change the route will have to change and then you are not in the same controller isn't? Please provide some code. – Raulucco Mar 27 '15 at 13:23