Angular Material - 对话框小部件
md-dialog是一个Angular指令,是一个容器元素,用于显示对话框。 它的元素 md-dialog-content 包含对话框的内容,md-dialog-actions 负责对话框操作。
mdDialog 是一项 Angular 服务,它在应用程序上打开一个对话框,向用户通报信息并帮助他们做出决策。
以下示例展示了 md-dialog 指令和 mdDialog 服务的使用以及角度对话框的使用。
am_dialog.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> <script language = "javascript"> angular .module('firstApplication', ['ngMaterial']) .controller('dialogController', dialogController); function dialogController ($scope, $mdDialog) { $scope.status = ''; $scope.items = [1,2,3,4,5]; $scope.showAlert = function(ev) { $mdDialog.show ( $mdDialog.alert() .parent(angular.element(document.querySelector('#dialogContainer'))) .clickOutsideToClose(true) .title('www.w3ccoo.com') .textContent('Welcome to www.w3ccoo.com') .ariaLabel('Welcome to www.w3ccoo.com') .ok('Ok!') .targetEvent(ev) ); }; $scope.showConfirm = function(event) { var confirm = $mdDialog.confirm() .title('Are you sure to delete the record?') .textContent('Record will be deleted permanently.') .ariaLabel('www.w3ccoo.com') .targetEvent(event) .ok('Yes') .cancel('No'); $mdDialog.show(confirm).then(function() { $scope.status = 'Record deleted successfully!'; }, function() { $scope.status = 'You decided to keep your record.'; }); }; $scope.showCustom = function(event) { $mdDialog.show ({ clickOutsideToClose: true, scope: $scope, preserveScope: true, template: '<md-dialog>' + ' <md-dialog-content>' + ' Welcome to www.w3ccoo.com' + ' </md-dialog-content>' + ' </md-dialog>', controller: function DialogController($scope, $mdDialog) { $scope.closeDialog = function() { $mdDialog.hide(); } } }); }; } </script> </head> <body ng-app = "firstApplication"> <div id = "dialogContainer" ng-controller = "dialogController as ctrl" layout = "row" ng-cloak> <md-content> <h4>Standard Alert</h4> <md-button class = "md-primary md-raised" ng-click = "showAlert($event)" flex = "100" flex-gt-md = "auto"> Alert </md-button> <h4>Confirm Dialog Box</h4> <md-button class = "md-primary md-raised" ng-click = "showConfirm($event)" flex = "100" flex-gt-md = "auto"> Confirm </md-button> <h4>Custom Dialog Box</h4> <md-button class = "md-primary md-raised" ng-click = "showCustom($event)" flex = "100" flex-gt-md = "auto"> Custom </md-button> <div ng-if = "status"> <br/> <b layout = "row" layout-align = "center center" class = "md-padding"> {{status}} </b> </div> </md-content> </div> </body> </html>
结果
验证结果。
❮ angular_material_widgets.html