Angular Material - Menu

The md-menu, an Angular directive, is a component to display addition options within the context of action performed. md-menu have two child elements. The first element is the trigger element and is used to open the menu. The second element is the md-menu-content which represents the content of the menu when menu is opened. The md-menu-content usually carries the menu items as md-menu-item.
The following table lists out the parameters and description of the different attributes of md-menu.
* md-position-mode
The position mode in the form of x, y. Default value is target,target. Right now the x axis also suppports target-right.
* md-offset
An offset to apply to the dropdown after positioning x, y. Default value is 0,0.
The following example shows the use of md-menu directive and also the uses of menus.
am_menus.htm
<html lang = "en">
   <head>
      <link rel = "stylesheet"
         href = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
      <link rel = "stylesheet" href = "https://fonts.googleapis.com/icon?family=Material+Icons">
      
      <script language = "javascript">
         angular
            .module('firstApplication', ['ngMaterial'])
            .controller('menuController', menuController);

         function menuController ($scope, $mdDialog) {
            var originatorEv;
            
            this.openMenu = function($mdOpenMenu, ev) {
               originatorEv = ev;
               $mdOpenMenu(ev);
            };
            
            this.menuItemClick = function(index) {
               $mdDialog.show (
                  $mdDialog.alert()
                    .title('TutorialsPoint.com')
                    .textContent('Menu Item clicked, index: ' + index)
                    .ok('OK')
                    .targetEvent(originatorEv)
               );
               originatorEv = null;
            };
         }                  
      </script>      
   </head>
   
   <body ng-app = "firstApplication"> 
      <div id = "menuContainer" ng-controller = "menuController as ctrl"
         layout = "row" ng-cloak>
         <div layout = "column" flex = "33" flex-sm = "100"
            layout-align = "center center">         
            <p>Default Menu</p>
            
            <md-menu>
               <md-button aria-label = "Sample Menu" class = "md-icon-button"
                  ng-click = "$mdOpenMenu($event)">
                  <md-icon md-menu-origin class = "material-icons">more_vert</md-icon>
               </md-button>
               
               <md-menu-content width = "6">
                  <md-menu-item ng-repeat = "item in [1, 2, 3]">
                     <md-button ng-click = "ctrl.menuItemClick($index)">
                        
                        <div layout = "row">
                           <md-icon md-menu-align-target class = "material-icons">
                              add</md-icon>
                           <p flex>Option {{item}}</p>
                        </div>
                        
                     </md-button>
                  </md-menu-item>
               </md-menu-content>
               
            </md-menu>
         </div>
         
         <div layout = "column" flex-sm = "100" flex = "33" layout-align = "center center">
            <p>Left Aligned Menu</p>
            <md-menu md-position-mode = "target-right target" >
               
               <md-button aria-label = "Sample Menu" class = "md-icon-button"
                  ng-click = "$mdOpenMenu($event)">
                  <md-icon md-menu-origin class = "material-icons">more_vert</md-icon>
               </md-button>
               
               <md-menu-content width = "4" >
                  <md-menu-item ng-repeat = "item in [1, 2, 3]">
                     <md-button ng-click = "ctrl.menuItemClick($index)">
                        
                        <div layout = "row">
                           <p flex>Option {{item}}</p>        
                           <md-icon md-menu-align-target class = "material-icons">
                              add</md-icon>					
                        </div>
                        
                     </md-button>
                  </md-menu-item>
               </md-menu-content>
            </md-menu>
         </div>

      </div>
   </body>
</html>
Verify the result.
Default Menu
Option {{item}}
Left Aligned Menu
Option {{item}}

    16 Lectures 
     1.5 hours 

 Anadi Sharma

    28 Lectures 
     2.5 hours 

 Anadi Sharma

    11 Lectures 
     7.5 hours 

 SHIVPRASAD KOIRALA

    16 Lectures 
     2.5 hours 

 Frahaan Hussain

    69 Lectures 
     5 hours 

 Senol Atac

    53 Lectures 
     3.5 hours 

 Senol Atac
 Print
 Add Notes
 Bookmark this page