• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

AngularJS中使用ngModal模态框实例

angularjs 搞代码 4年前 (2021-12-31) 45次浏览 已收录 0个评论

本篇文章主要介绍了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中注入模态框

 var app = angular.module('app', ['ui.bootstrap']); app.controller('modalController', function($scope, $rootScope,$modal) { $scope.openModel = 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() { $mod<span style="color:transparent">来源gaodai#ma#com搞*代#码网</span>alInstance.dismiss('cancel'); } }); 

添加事件触发显示模态框

 <button>打开模态框</button>

html

   <title>ng-model模态框</title> <button>打开模态框</button>

以上就是AngularJS中使用ngModal模态框实例的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:AngularJS中使用ngModal模态框实例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址