Angularjs 使用角度指令时,在页面上单击时防止角度模式弹出窗口关闭

Angularjs 使用角度指令时,在页面上单击时防止角度模式弹出窗口关闭,angularjs,Angularjs,我正在为模式弹出窗口使用指令 mymodule.directive('modalDialog', function() { return { restrict: 'E', scope: { show: '=' }, replace: true, transclude: true, link: function(scope, element, attrs) { scope.dialogStyle = {};

我正在为模式弹出窗口使用指令

mymodule.directive('modalDialog', function() {
  return {
    restrict: 'E',
    scope: {
      show: '='
    },
    replace: true, 
    transclude: true,
    link: function(scope, element, attrs) {
      scope.dialogStyle = {};
      if (attrs.width)
        scope.dialogStyle.width = attrs.width;
      if (attrs.height)
        scope.dialogStyle.height = attrs.height;
        if (attrs.overflow)
        scope.dialogStyle.overflow = attrs.overflow;
      scope.hideModal = function() {

        scope.show = false;
      };
    },
    template: "<div class='ng-modal' ng-show='show'><div class='ng-modal-overlay' ng-click='hideModal()'></div><div class='ng-modal-dialog' ng-style='dialogStyle'><div class='ng-modal-close' ng-click='hideModal()'><i class='fa fa-times-circle'></i></div><div class='ng-modal-dialog-content' ng-transclude></div></div></div>"// See below
  };
});
mymodule.directive('modalDialog',function(){
返回{
限制:'E',
范围:{
显示:'='
},
替换:正确,
是的,
链接:函数(范围、元素、属性){
scope.dialogStyle={};
if(属性宽度)
scope.dialogStyle.width=attrs.width;
if(属性高度)
scope.dialogStyle.height=attrs.height;
if(属性溢出)
scope.dialogStyle.overflow=attrs.overflow;
scope.hideModal=函数(){
scope.show=false;
};
},
模板://请参阅下面的
};
});
它工作正常,但当我单击页面中的任意位置时,模式弹出窗口关闭。我如何防止它???

覆盖元素,该元素带有指令,在单击事件时调用
隐藏事件。

删除此项将阻止弹出窗口关闭。

要停止单击事件,请在后台html标记上添加以下代码:

ng-click="$event.preventDefault()"

查看演示

hi,实际上我的问题是,如果我单击“取消”按钮或当我校准hideModal()时,它工作正常,但如果我单击页面中除“取消”按钮或当我校准hideModal()外的任何位置模态弹出窗口关闭。如何防止此问题?它是关闭的还是仍然打开的?它是关闭的,但每当我单击页面时,这意味着如果我单击除模态弹出窗口之外的其他位置,它的关闭就是我的问题。如果我单击除模态外,它不应关闭。它应仅在单击取消按钮或调用此功能时关闭hideModal()@Vivekvetrri您能删除
ng click='hideModal()吗“
属性在模板中的
ng modal overlay
div
元素上,然后看看会发生什么?很好的人。很抱歉错过了沟通。你真的很棒。非常感谢你。当我想打开模态弹出窗口时,我正在使用此代码。假设我把你的代码放错了。你能解释一下我应该把此代码放在哪里吗?你可以像这样使用它:
Selected:{{Selected.item}