Angular Material - 菜单小部件
md-menu 是一个 Angular 指令,是一个在执行操作的上下文中显示附加选项的组件。 md-menu 有两个子元素。 第一个元素是触发元素,用于打开菜单。 第二个元素是md-menu-content,它表示菜单打开时菜单的内容。 md-menu-content 通常带有 md-menu-item 形式的菜单项。
属性
下表列出了md-menu不同属性的参数及说明。
Sr.No | 参数和描述 |
---|---|
1 | * md-position-mode x、y 形式的位置模式。 默认值为目标,目标。 现在 x 轴也支持目标右侧。 |
2 | * md-offset 定位 x、y 后应用于下拉列表的偏移量。 默认值为 0,0。 |
示例
以下示例显示了 md-menu 指令的使用以及菜单的使用。
am_menus.html
<html lang = "en"> <head> <link rel = "stylesheet" href = "https://www.w3ccoo.com/lib/angular_material/1.0.0/angular-material.min.css"> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular.min.js"></script> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular-animate.min.js"></script> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular-aria.min.js"></script> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular-messages.min.js"></script> <script src = "https://www.w3ccoo.com/lib/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('www.w3ccoo.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>
结果
验证结果。
❮ angular_material_widgets.html