How do I toggle an ng-show in AngularJS based on a boolean?

前端 未结 6 628
日久生厌
日久生厌 2020-12-22 20:59

I have a form for replying to messages that I want to show only when isReplyFormOpen is true, and everytime I click the reply button I want to toggle whether th

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 21:23

    It's worth noting that if you have a button in Controller A and the element you want to show in Controller B, you may need to use dot notation to access the scope variable across controllers.

    For example, this will not work:

    
    

    To solve this, create a global variable (ie. in Controller A or your main Controller):

    .controller('ControllerA', function ($scope) {
      $scope.global = {};
    }
    

    Then add a 'global' prefix to your click and show variables:

    
    

    For more detail, check out the Nested States & Nested Views in the Angular-UI documentation, watch a video, or read understanding scopes.

提交回复
热议问题