加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS中使用ngModal模态框

发布时间:2020-12-17 08:17:34 所属栏目:安全 来源:网络整理
导读:在AngularJS中使用模态框需要引用的文件: angular.js 1.5.5 ui.bootstrap-tpls.js 0.11.2 bootstrap.css 3.3.7 需要注意版本要一致,高版本的不支持这种方法,会出错 将需要弹出的模态框的内容写在 script 标签中,指明属性,放在页面中 script type= "text
  • 在AngularJS中使用模态框需要引用的文件:
    • angular.js 1.5.5
    • ui.bootstrap-tpls.js 0.11.2
    • bootstrap.css 3.3.7

需要注意版本要一致,高版本的不支持这种方法,会出错


  • 将需要弹出的模态框的内容写在 script 标签中,指明属性,放在页面中
<script type="text/ng-template" id="modal.html"> 
<div>
    <div class="modal-header">
        <h3 class="modal-title" align="center">
            标题信息
        </h3>
    </"modal-body">
        <div align="center">
            模态框内容
        </div>
    </"modal-footer">
        <button class="btn btn-primary" ng-click="ok()">
            确认
        </button>
        <button class="btn btn-warning" ng-click="cancel()">
            退出
        </button>
    </div>
</script>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 在App和Controller中注入模态框
var app = angular.module('app',['ui.bootstrap']);
app.controller('modalController',function($scope,$rootScope,$modal) {
    $scope.openModel = () {
            var modalInstance = $modal.open({
                templateUrl : 'modal.html',//script标签中定义的id
                controller : 'modalCtrl',0);">//modal对应的Controller
                resolve : {
                    data : () {//data作为modal的controller传入的参数
                         return data;//用于传递数据
                    }
                }
            })
        }
}

//模态框对应的Controller
app.controller($modalInstance,data) {
    $scope.data= data;

    //在这里处理要进行的操作 
    $scope.ok = () {
        $modalInstance.close();
    };
    $scope.cancel = $modalInstance.dismiss('cancel');
    }
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 添加事件触发显示模态框
<button ng-click="openModal()">打开模态框</button>
  • 1

  • html
<!DOCTYPE html> html ng-app="app" ng-controller="modalController"> head> title>ng-model模态框title> link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> body> button> script type="text/ng-template" id="modal.html"> <div> div class="modal-header"> h3 "modal-title" align="center"> 标题信息 h3> div> "modal-body"> "center"> 模态框内容 br> {{data}} </div> </div> "modal-footer"> "btn btn-primary" "ok()"> 确认 "btn btn-warning" "cancel()"> 退出 div> script> src="https://cdn.bootcss.com/angular.js/1.5.5/angular.min.js">"https://cdn.bootcss.com/angular-ui-bootstrap/0.11.2/ui-bootstrap-tpls.min.js">"text/javascript"> 'ui.bootstrap']); app.controller(($scope,$rootScope,$modal) { var data = "通过modal传递的数据"; $scope.openModal = () { var modalInstance = $modal.open({ templateUrl : //script标签中定义的id controller : //modal对应的Controller resolve : { data : //data作为modal的controller传入的参数 //用于传递数据 } } }) } }) //模态框对应的Controller app.controller(//在这里处理要进行的操作 $scope.ok = () { $modalInstance.close(); }; $scope.cancel = () { $modalInstance.dismiss('cancel'); } }); html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读