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
- <! DOCTYPE HTML>
- <HTML ng-app="Modaldemo">
- <head>
- <title></title>
- <link href= "lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
- <script src="Lib/angular/angular.min.js"></script>
- <script src="Lib/bootstrap-gh-pages/ui-bootstrap-tpls-0.7.0.min.js"></ Script>
- <script src="Lib/angular/i18n/angular-locale_zh-cn.js"></script>
- </head>
- <body>
- <div ng-controller="Modaldemoctrl">
- <script type="text/ng-template" id="mymodalcontent.html" />
- <div class="Modal-header">
- <h3>i ' m a modal! </h3>
- </div>
- <div class="Modal-body">
- <ul>
- <li ng-repeat="item in Items"><a
- ng-click="Selected.item = Item">{{item}}</a></li>
- </ul>
- Selected: <b>{{Selected.item}}</b>
- </div>
- <div class="Modal-footer">
- <button class="btn btn-primary" ng-click="OK ()">ok</button>
- <button class="btn btn-warning" ng-click="Cancel ()">cancel</ button>
- </div>
- </Script>
- <button class="btn" ng-click="open ()">open me! </button>
- </div>
- <script>
- var modaldemo = angular.module (' Modaldemo ', [' ui.bootstrap ']);
- var modaldemoctrl = function ($scope, $modal, $log) {
- $Scope.items = [' item1 ', ' item2 ', ' item3 '];
- $Scope.open = function () {
- var modalinstance = $modal. Open ({
- Templateurl: ' mymodalcontent.html ',
- Controller:modalinstancectrl,
- Resolve: {
- Items:function () {
- return $scope. Items;
- }
- }
- });
- ModalInstance.opened.then (function () {///modal window after opening
- Console.log (' modal is opened ');
- });
- ModalInstance.result.then (function (result) {
- Console.log (result);
- }, function (reason) {
- Console.log (reason);//Click on the blank area, always output backdrop
- Click Cancel, then the
- $log. info (' Modal dismissed at: ' + new Date ());
- });
- };
- };
- var modalinstancectrl = function ($scope, $modalInstance, items) {
- $scope.items = items;
- $scope.selected = {
- Item: $scope. items[0]
- };
- $Scope.ok = function () {
- $modalInstance. Close ($scope. selected);
- };
- $Scope.cancel = function () {
- $modalInstance. Dismiss (' Cancel ');
- };
- };
- </Script>
- </body>
- </html>
Angularjs pop-up box $modal