AngularJS中如何使用ngModal模态框的实例详解
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了AngularJS中如何使用ngModal模态框的实例详解,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3062字,纯文字阅读大概需要5分钟。
内容图文
![AngularJS中如何使用ngModal模态框的实例详解](/upload/InfoBanner/zyjiaocheng/302/66ee535a11e148c78a3b423ce5e0cc33.jpg)
在AngularJS中使用模态框需要引用的文件:
angular.js 1.5.5
ui.bootstrap-tpls.js 0.11.2
bootstrap.css 3.3.7
需要注意版本要一致,高版本的不支持这种方法,会出错
将需要弹出的模态框的内容写在 script 标签中,指明属性,放在页面中
在App和Controller中注入模态框
添加事件触发显示模态框
<button ng-click="openModal()">打开模态框</button>
html
<!DOCTYPE html> <html ng-app="app" ng-controller="modalController"> <head> <title>ng-model模态框</title> </head> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet"> <body> <button ng-click="openModal()">打开模态框</button> <script type="text/ng-template" id="modal.html"> <p> <p class="modal-header"> <h3 class="modal-title" align="center"> 标题信息 </h3> </p> <p class="modal-body"> <p align="center"> 模态框内容 <br> {{data}} </p> </p> <p class="modal-footer"> <button class="btn btn-primary" ng-click="ok()"> 确认 </button> <button class="btn btn-warning" ng-click="cancel()"> 退出 </button> </p> </p> </script> <script src="https://cdn.bootcss.com/angular.js/1.5.5/angular.min.js"></script> <script src="https://cdn.bootcss.com/angular-ui-bootstrap/0.11.2/ui-bootstrap-tpls.min.js"></script> <script type="text/javascript"> var app = angular.module('app', ['ui.bootstrap']); app.controller('modalController', function($scope, $rootScope, $modal) { var data = "通过modal传递的数据"; $scope.openModal = function() { var modalInstance = $modal.open({ templateUrl : 'modal.html',//script标签中定义的id controller : 'modalCtrl',//modal对应的Controller resolve : { data : function() {//data作为modal的controller传入的参数 return data;//用于传递数据 } } }) } }) //模态框对应的Controller app.controller('modalCtrl', function($scope, $modalInstance, data) { $scope.data= data; //在这里处理要进行的操作 $scope.ok = function() { $modalInstance.close(); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); } }); </script> </body> </html>
以上就是AngularJS中如何使用ngModal模态框的实例详解的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的AngularJS中如何使用ngModal模态框的实例详解全部内容,希望文章能够帮你解决AngularJS中如何使用ngModal模态框的实例详解所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。