最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

AngularJS中如何使用ngModal模态框的实例详解

来源:动视网 责编:小OO 时间:2020-11-27 20:22:26
文档

AngularJS中如何使用ngModal模态框的实例详解

在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;
推荐度:
导读在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;


本篇文章主要介绍了AngularJS中使用ngModal模态框实例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

在AngularJS中使用模态框需要引用的文件:

  1. angular.js 1.5.5

  2. ui.bootstrap-tpls.js 0.11.2

  3. 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模态框的实例详解

在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;
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top