0

The logout() has the code to open model. I only want logout() function to be called if the angularjs object value inside rootscope is true.. How do I check from javascript what is inside the rootscope object?

<body ng-controller="myController">
    <div id="myPopup" modal custom-model fade" style="left:20%"
            data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="custom-modal-header">
                    </div>
                    <div class="custom-modal-body">
                    </div>
                    <div class="custom-modal-footer">
                    </div>
                </div>
            </div>
        </div>  



<script type="text/javascript">
logout();//here add if rootscope.mydata == true 
</script>  
</body>
amphetamachine
  • 27,620
  • 12
  • 60
  • 72
Baldo
  • 1
  • 1

1 Answers1

0

The direct answer would be, inject $rootScope into your controller:

angular
    .module("yourAppName")
    .controller("myController", function ($rootScope) {
        // $rootScope is available here!
        if ($rootScope..mydata) {
            // show modal?
        }
    })

You didn't specify what you wanted to start the logout function, a button click or when the controller loads, so adjust it as you see fit.

javinor
  • 674
  • 4
  • 8