- Angular Material 教程
- Angular Material - 首页
- Angular Material - 概览
- 环境设置
- Angular Material - 自动完成
- Angular Material - 底部面板
- Angular Material - 卡片
- Angular Material - 部件
- Angular Material - 布局
- Angular Material - 输入
- Angular Material - 图标
- Angular Material - 网格
- Angular Material - 侧边导航
- Angular Material - 快速拨号按钮
- Angular Material - 副标题
- Angular Material - 滑动
- Angular Material - 控件开关
- Angular Material - 主题
- Angular Material - 通知
- Angular Material - 排版
- Angular Material - 虚拟重复
- Angular Material - 白框
- Angular Material 有用资源
- Angular Material - 快速指南
- Angular Material - 有用资源
- Angular Material - 讨论
Angular Material - 菜单
md-menu 是一个 Angular 指令,是一个组件,用于在执行操作的环境中显示附加选项。 md-menu 有两个子元素。第一个元素是触发器元素,用于打开菜单。第二个元素是 md-menu-content,它表示菜单打开后菜单的内容。 md-menu-content 通常将菜单项作为 md-menu-item 携带。
属性
下表列出了 md-menu 中不同属性的参数及说明。
序号 | 参数及说明 |
---|---|
1 | * md-position-mode 定位模式,x、y 形式。默认值为 target、target。现在 x 轴还支持 target-right。 |
2 | * md-offset 应用于定位后的下拉框中的偏移量,x、y 形式。默认值为 0、0。 |
示例
以下示例展示了 md-menu 指令和菜单的用法。
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>
结果
验证结果。
angular_material_widgets.htm
广告