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

使用angularjs模态框$modal

发布时间:2020-12-17 09:38:29 所属栏目:安全 来源:网络整理
导读:使用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:为模态框添加样式


用例:
$scope.openAuthenticationViewPage = function(){
            singleModal.open({
                templateUrl: 'terminal/authentication/authentication-conf.html',//指定模板路径
                controller: 'TerminalAuthConfController',//指定controller
                size:'lg',//模态框大小
                backdrop:true,//控制背景
                keyboard:false//禁用ESC键
            },function(result) {
                $scope.toggleManager.getauthinfo();
            },function(reason) {
                $scope.toggleManager.AuthViewInit();
            });

        };
下面是做了一个简单的封装,
.factory('singleModal',['$modal',function($modal) {
		var vm = this;
		vm.modal = null;
		vm.draggable = function(){
            $(".modal-content").draggable({ 
            	handle: ".modal-header",cursor: 'move',refreshPositions: false  
			});  
		};

		return {
			open: function(param,result_fc,reason_fc) {

				if (vm.modal != null) {
					return null;
				}
				vm.modal = $modal.open(param);

				vm.modal.result.then(function(result) {
					vm.modal = null;
					if(result_fc!= null){
						result_fc(result);
					}				
				},function(reason){
					vm.modal = null;
					if(reason_fc!= null){
						reason_fc(reason);
					}				
				});
				
				vm.modal.opened.then(function() { 
                    setTimeout(vm.draggable,3000);
                });  

				return vm.modal;
			}
		}
	}])

(编辑:李大同)

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

    推荐文章
      热点阅读