使用angularjs模态框$modal

前端之家收集整理的这篇文章主要介绍了使用angularjs模态框$modal前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用angularjs提供的$modal可以快捷的创建新的弹出框,并且自带了一些比较好用的属性方法,方便我们进行开发。

在开发中碰到的问题就是,当登录用户权限不同的时候,我们提供不同的权限控制和页面展示,当非管理员登录的时候,弹出的页面是不允许关闭的,即不允许用户

操作主页面内容,只能在弹出框中操作。

属性
templateURL:指定加载模板路径
$scope:创建一个在弹出模板页面上的作用域
$controller:为$modal指定controller,初始化$scope
resolve:定义一个成员并将它传递给$modal指定的控制器,相当于routes的一个resolve属性,如果需要传递一个object对象,需要使用angular.copy()
backdrop:控制背景,默认true,false表示没有背景,显示空白。"static"--背景依然存在,但是点击模态框以外的地方,模态框不会消失
keyboard:true使用ESC键将会关闭模态框,false取消ESC键作用
windclass:为模态框添加样式


用例:
  1. $scope.openAuthenticationViewPage = function(){
  2. singleModal.open({
  3. templateUrl: 'terminal/authentication/authentication-conf.html',//指定模板路径
  4. controller: 'TerminalAuthConfController',//指定controller
  5. size:'lg',//模态框大小
  6. backdrop:true,//控制背景
  7. keyboard:false//禁用ESC键
  8. },function(result) {
  9. $scope.toggleManager.getauthinfo();
  10. },function(reason) {
  11. $scope.toggleManager.AuthViewInit();
  12. });
  13.  
  14. };
下面是做了一个简单的封装,
  1. .factory('singleModal',['$modal',function($modal) {
  2. var vm = this;
  3. vm.modal = null;
  4. vm.draggable = function(){
  5. $(".modal-content").draggable({
  6. handle: ".modal-header",cursor: 'move',refreshPositions: false
  7. });
  8. };
  9.  
  10. return {
  11. open: function(param,result_fc,reason_fc) {
  12.  
  13. if (vm.modal != null) {
  14. return null;
  15. }
  16. vm.modal = $modal.open(param);
  17.  
  18. vm.modal.result.then(function(result) {
  19. vm.modal = null;
  20. if(result_fc!= null){
  21. result_fc(result);
  22. }
  23. },function(reason){
  24. vm.modal = null;
  25. if(reason_fc!= null){
  26. reason_fc(reason);
  27. }
  28. });
  29. vm.modal.opened.then(function() {
  30. setTimeout(vm.draggable,3000);
  31. });
  32.  
  33. return vm.modal;
  34. }
  35. }
  36. }])

猜你在找的Angularjs相关文章