Angularjs pop-up box $modal

Source: Internet
Author: User

 angularjs pop-up box $modalTags: angularjs2015-11-04 09:50 8664 People read Comments (1) favorite reports Classification:Angularjs (3)

$modal There is only one method: Open, the properties of the method are:

    • templateUrl: The address of the modal window

    • template:用于显示html标签

    • scope: A scope for modal content usage (in fact, $modal会创建一个当前作用域的子作用域 ) defaults to$rootScope

    • controller: Initializes the $scope for the $modal specified controller, which is available for $modalInstance injection

    • resolve: Defines a member and passes it to the controller specified by $modal, which is equivalent to a Reslove property of routes, and if a Objec object needs to be passed, use Angular.copy ()

    • backdrop: Control background, allowable value: True (default), False (no background), " static "-background is present, but modal window does not close when clicking outside modal window

    • keyboard: When ESC is pressed, the modal dialog box is closed and the default is Ture

    • windowClass: Specifies a class and is added to the modal window

The Open method returns an instance that has the following properties:

    • close(result): Closes the modal window and passes a result

    • dismiss(reason): Undo modal method and pass a reason

    • result: A contract that is passed when the modal window is closed or revoked

    • opened: A contract that passes when the modal window is open and content is loaded

In addition, $modalInstance has expanded two methods $close(result)$dismiss(reason), these methods are easy to close the window and do not require an additional controller

[HTML]View PlainCopy
  1. <! DOCTYPE HTML>
  2. <HTML ng-app="Modaldemo">
  3. <head>
  4. <title></title>
  5. <link href= "lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  6. <script src="Lib/angular/angular.min.js"></script>
  7. <script src="Lib/bootstrap-gh-pages/ui-bootstrap-tpls-0.7.0.min.js"></ Script>
  8. <script src="Lib/angular/i18n/angular-locale_zh-cn.js"></script>
  9. </head>
  10. <body>
  11. <div ng-controller="Modaldemoctrl">
  12. <script type="text/ng-template" id="mymodalcontent.html" />
  13. <div class="Modal-header">
  14. <h3>i ' m a modal! </h3>
  15. </div>
  16. <div class="Modal-body">
  17. <ul>
  18. <li ng-repeat="item in Items"><a
  19. ng-click="Selected.item = Item">{{item}}</a></li>
  20. </ul>
  21. Selected: <b>{{Selected.item}}</b>
  22. </div>
  23. <div class="Modal-footer">
  24. <button class="btn btn-primary" ng-click="OK ()">ok</button>
  25. <button class="btn btn-warning" ng-click="Cancel ()">cancel</ button>
  26. </div>
  27. </Script>
  28. <button class="btn" ng-click="open ()">open me! </button>
  29. </div>
  30. <script>
  31. var modaldemo = angular.module (' Modaldemo ', [' ui.bootstrap ']);
  32. var modaldemoctrl = function ($scope, $modal, $log) {
  33. $Scope.items = [' item1 ', ' item2 ', ' item3 '];
  34. $Scope.open = function () {
  35. var modalinstance = $modal. Open ({
  36. Templateurl: ' mymodalcontent.html ',
  37. Controller:modalinstancectrl,
  38. Resolve: {
  39. Items:function () {
  40. return $scope. Items;
  41. }
  42. }
  43. });
  44. ModalInstance.opened.then (function () {///modal window after opening
  45. Console.log (' modal is opened ');
  46. });
  47. ModalInstance.result.then (function (result) {
  48. Console.log (result);
  49. }, function (reason) {
  50. Console.log (reason);//Click on the blank area, always output backdrop
  51. Click Cancel, then the
  52. $log. info (' Modal dismissed at: ' + new Date ());
  53. });
  54. };
  55. };
  56. var modalinstancectrl = function ($scope, $modalInstance, items) {
  57. $scope.items = items;
  58. $scope.selected = {
  59. Item: $scope. items[0]
  60. };
  61. $Scope.ok = function () {
  62. $modalInstance. Close ($scope. selected);
  63. };
  64. $Scope.cancel = function () {
  65. $modalInstance. Dismiss (' Cancel ');
  66. };
  67. };
  68. </Script>
  69. </body>
  70. </html>

Angularjs pop-up box $modal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.