如何隐藏我的' DIV'单击页面上的任何位置

时间:2016-03-29 05:13:25

标签: angularjs angularjs-directive

我有两个HTML元素

<input class="button bttn-default" 
       type="button" 
       value="Preview" 
       ng-mouseover="showDropDown();" 
       ng-click="preview()"
       />

<div id="deviceList" 
     class="dropdown-content" 
     ng-hide="showChannelDropDown"
     >

    <a href="#" ng-click="hideDropDown('desktop')">Desktop</a><br/>
    <a href="#" ng-click="hideDropDown('mobile')">Mobile</a><br/>
    <a href="#" ng-click="hideDropDown('tablet')">Tablet</a><br/>
</div>

如果我选择该选项,将使用以下代码打开一个新窗口

<div id="outerdiv">
    <div id="dynamicWidgetDiv"></div>
</ div>

我想隐藏&#39; div&#39; div带有id&#39; deviceList&#39;的元素,当我点击页面上除该元素之外的任何地方。我的angularjs代码如下......

$scope.hideDropDown = function(v){ 
                         console.log(v);  
                         $scope.showChannelDropDown=true;
                         $scope.preview(v);
                      }

angular.element(document).on('click', function ($scope) {        
    alert("test");
    $scope.showChannelDropDown = true;
});
$scope.showChannelDropDown=true;           
$scope.showDropDown=function(){
    $scope.showChannelDropDown=false;
}

但它不起作用。事件

angular.element(document).on('click',function(){})

正在被召唤但是&#39; div&#39;不要躲藏单击&#39; DIV&#39;时不应调用此功能。 id =&#39; outerdiv&#39;。

你可以给出解决方案......

0 个答案:

没有答案