In Angular Material like md-sidenav always opens
Please take a look at this code snippet. You can mainly use $mdSidenav("sidenavId").toggle()
sidenav to switch.
angular.module('materialApp', ['ngMaterial', 'ngAnimate'])
.controller('homeCtrl', ['$scope', '$mdSidenav', function($scope, $mdSidenav) {
$scope.toggleSideNav = function() {
$mdSidenav('leftNav').toggle();
};
}]);
.ma-sidenav {
background: rgb(16,108,200);
}
.btn-row {
padding-top: 30px;
text-align: center;
}
.btn-toggle {
display: inline-block;
}
.sidenav-item {
padding: 10px 10px 10px 30px;
color: white;
}
<link href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.js"></script>
<body ng-app="materialApp">
<section ng-controller="homeCtrl">
<md-sidenav class="md-sidenav-left md-whiteframe-z2 ma-sidenav" md-component-id="leftNav">
<div class="sidenav-item">Item 1</div>
<div class="sidenav-item">Item 2</div>
<div class="sidenav-item">Item 3</div>
<div class="sidenav-item">Item 4</div>
</md-sidenav>
<md-content flex layout-padding>
<div class="btn-row">
<md-button class="md-raised btn-toggle" ng-click="toggleSideNav()">Toggle SideNav</md-button>
</div>
</md-content>
</section>
</body>
source to share
You can leave the Navbar open for any view if you like by adding the following attributes to it:
md-is-locked-open="$mdMedia('gt-md')"
Check Angular Docs for reference.
source to share
Alas, #Gabriel's solution is incomplete. from the description https://material.angular.io/components/sidenav/api#MatSidenav
Whether the drawer can be closed with the escape key or by clicking on the backdrop.
but we have 3 options how to close sidenav
and 3d when you click on some element (?) in it. to prevent you need to override the callback or for example i used sidenav
for responsive design and this answer was helpful to me https://github.com/angular/material2/issues/1130#issuecomment-299888690
source to share