md-sidenav角度材料阻止外部点击关闭

时间:2016-03-11 09:18:25

标签: javascript html angularjs angular-material

如果我在它外面点击(如果我点击md背景),我需要阻止sidenav关闭。例如,对于md对话框,有一个名为:clickOutsideToClose的指令,其中false表示如果单击“外部”,它不会关闭对话框。我需要这样的东西。有可能吗?以下是导航的示例:http://codepen.io/ThomasBurleson/pen/LEZvWw

<div ng-app="sidenavDemo1" ng-controller="AppCtrl" layout="column" layout-fill>
  <section layout="row" flex>
    <md-sidenav class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$mdMedia('gt-md')">
      <md-toolbar class="md-theme-indigo" layout="row">
        <h1 class="md-toolbar-tools">Sidenav Left</h1>
        <span flex>
        <md-menu>
      <md-button aria-label="Open phone interactions menu" class="md-icon-button" ng-click="ctrl.openMenu($mdOpenMenu, $event)">
        <md-icon md-menu-origin class="material-icons">phone</md-icon>
      </md-button>
      <md-menu-content width="4">
        <md-menu-item>
          <md-button ng-click="ctrl.redial($event)">
            <md-icon md-svg-icon="call:dialpad" md-menu-align-target></md-icon>
            Redial
          </md-button>
        </md-menu-item>
        <md-menu-item>
          <md-button disabled="disabled" ng-click="ctrl.checkVoicemail()">
            <md-icon md-svg-icon="call:voicemail"></md-icon>
            Check voicemail
          </md-button>
        </md-menu-item>
        <md-menu-divider></md-menu-divider>
        <md-menu-item>
          <md-button ng-click="ctrl.toggleNotifications()">
            <md-icon md-svg-icon="social:notifications-{{ctrl.notificationsEnabled ? 'off' : 'on'}}"></md-icon>
            {{ctrl.notificationsEnabled ? 'Disable' : 'Enable' }} notifications
          </md-button>
        </md-menu-item>
      </md-menu-content>
    </md-menu> 
      </md-toolbar>
      <md-content class="md-padding" ng-controller="LeftCtrl">
        <md-button ng-click="close()" class="md-primary" hide-gt-md>
          Close Sidenav Left
        </md-button>
        <p hide-md show-gt-md>
          This sidenav is locked open on your device. To go back to the default behavior,
          narrow your display.
        </p>
        <p> 
        The "right" sideNav is open = {{isOpen()}} </p>
      </md-content>
    </md-sidenav>
    <md-content flex class="md-padding">
      <div layout="column" layout-fill layout-align="center center">
        <p>
        The left sidenav will 'lock open' on a medium (>=960px wide) device.
        </p>
        <div>
          <md-button ng-click="toggleLeft()" class="md-primary" hide-gt-md>
            Toggle left
          </md-button>
        </div>
        <div>
          <md-button ng-click="toggle()" class="md-primary" >
            Toggle right
          </md-button>
        </div>
      </div>
    </md-content>
    <md-sidenav class="md-sidenav-right md-whiteframe-z2" md-component-id="right">
      <md-toolbar class="md-theme-light">
        <h1 class="md-toolbar-tools">Sidenav Right</h1>
      </md-toolbar>
      <md-content ng-controller="RightCtrl" class="md-padding">
        <md-button ng-click="close()" class="md-primary">
          Close Sidenav Right
        </md-button>
      </md-content>
    </md-sidenav>
  </section>
</div>

2 个答案:

答案 0 :(得分:1)

您只需使用md-is-locked-open即可。单击相应按钮时,将其设为truefalse

检查以下链接。 http://codepen.io/next1/pen/aNZYJb

答案 1 :(得分:0)

您正在寻找md-disable-backdrop

示例:

<md-sidenav 
class="md-sidenav-right" 
md-component-id="right" 
md-disable-backdrop> ... 
</md-sidenav>