0

the view in the index file is not updating. here are the code snippits.

index:

<body class="container" ng-controller="indexController">
  <div ng-if="isLogin">
      <div class="wrapper">
          <div ng-include="src/partial/header.html"></div>
          <div ng-include="src/partial/leftNavBar.html"></div>
          <div ui-view></div>
          <div ng-include="src/partial/footer.html"></div>
      </div>
  </div>
  <div ng-if="!isLogin">
      <div ui-view></div>
  </div>
  </body>

indexController:

.controller('indexController', indexController);
        function IndexController(global, $scope){

            function setupLogin(){
                $scope.isLogin = global.getLogin();

            };
            $scope.$on('UPDATE_Login', setupLogin);
        }

and my Login Controller:

.controller('Login', Login);

  /* @ngInject */
    function Login(auth, $location, global, $scope){
        var vm = this;

        vm.loginBtn = function login(credentials){
            vm.dataLoading = true;
            auth.loginService(credentials).then(function (result){
                vm.dataLoading = false;
                if(result.responseCode === '00'){
                    global.setLogin(true);
                    $scope.$broadcast('UPDATE_Login');
                    $location.path('/default');
                }else {
                    vm.errorMessage = result.responseDescription;
                }
            });

        }
}

the problem that i am facing is that when the scope from the login controller broadcast, it doesn't show and includes my partial header navigation and footer files.

am i missing something here ?

Shauzab
  • 65
  • 1
  • 4
  • 11
  • why the check for result.responseCode === '00' - is this something you are returning ? You should really follow REST conventions i.e return 200. Also I think you should be using $rootScope.$broadcast rather than $scope.$broadcast. – markyph Oct 07 '15 at 07:16
  • yeah it is something i am returning. it checks if the server has authenticated the user or not – Shauzab Oct 07 '15 at 07:30
  • I suspect this line is the culprit - $location.path('/default');I think you should write this line with in setupLogin function (after setting $scope.isLogin = global.getLogin();). – Rabi Oct 07 '15 at 07:34
  • I second that you should try using `$rootScope.$broadcast` instead. – Icycool Oct 07 '15 at 08:05

1 Answers1

0

have you tried to to wrap setupLogin() in timeOut:

.controller('indexController', indexController);
    function IndexController(global, $scope,$timeout){

        function setupLogin(){

            $timeout(()=>{
                $scope.isLogin = global.getLogin();
              },100); 

        };
        $scope.$on('UPDATE_Login', setupLogin);
    }

sometimes it helps with problems like this

goodluck

David
  • 633
  • 8
  • 6