Search code examples
angularjsangularjs-scope

AngularJS updating scope data of another controller


I have an AngularJS webapp where upon logging out I am redirected to the login page. I wanted certain fields in the login page to be hidden based on some data passed back from the logout service in the backend.

Is there a way to do this ? I just need to update a variable in the login controller js but I am not sure how to do that from the logout controller js ?

Please help completely new to AngularJS!


Solution

  • You need to use the "value" option in your app

    angular.module('yourAppName')
         .value('Config', null);
    

    then you need to inject it in your controllers to make them communicate each others

    .controller('controllerLogout', function(Config){
    //do something that update Config
    }
    
    .controller('MainController' function(Config){
          //use Config here to bind it in a ng-show in HTML controlled by 
          //coontroller itself
    }