我正在使用Angular Material的sidenav。我动态地打开了sidenav。面板出现在背景中。用户可以单击背景以关闭sidenav。我需要的是在点击背景时禁用sidenav的关闭。你能帮我解决这个问题吗?
答案 0 :(得分:2)
你去了 - CodePen
技巧是访问背景元素并禁用其上的指针事件。
标记
<div ng-controller="AppCtrl" layout="column" style="height:500px;" ng-cloak="" class="sidenavdemoBasicUsage" ng-app="MyApp">
<section id="section" layout="row" flex="">
<md-content flex="" layout-padding="">
<div layout="column" layout-fill="" layout-align="top center">
<div>
<md-button ng-click="toggleRight()" ng-hide="isOpenRight($event)" class="md-primary">
Toggle right
</md-button>
</div>
</div>
<div flex=""></div>
</md-content>
<md-sidenav class="md-sidenav-right md-whiteframe-4dp" md-component-id="right">
<md-content ng-controller="RightCtrl" layout-padding="">
<md-button ng-click="close()" class="md-primary">
Close Sidenav Right
</md-button>
</md-content>
</md-sidenav>
</section>
</div>
JS
angular
.module('MyApp',['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function ($scope, $timeout, $mdSidenav, $log, $element) {
var section,
backdrop;
$scope.toggleRight = function() {
$mdSidenav('right')
.toggle()
.then(function () {
$log.debug("toggle right is done");
// Disable pointer events on backdrop
section = angular.element($element[0].querySelector('#section'));
backdrop = section[0].children[0];
backdrop.style.pointerEvents = 'none';
});
}
})
.controller('RightCtrl', function ($scope, $timeout, $mdSidenav, $log) {
$scope.close = function () {
$mdSidenav('right').close()
.then(function () {
$log.debug("close RIGHT is done");
});
};
});