ng-click文档的任何位置?

时间:2015-07-16 12:16:32

标签: angularjs

我有这个登录菜单及其显示点击,但每当我点击它仍然打开。现在我需要实现当用户点击页面上的任何地方$ scope.loginOpened = false ...(用登录菜单关闭该div)我怎么能这样做?有什么建议吗? 这是登录菜单的一个示例:

$scope.toggleLoggedIn = function () {
            $scope.loggedInOpened = !$scope.loggedInOpened;
            $scope.languagesOpened = false;
            $scope.loginOpened = false;  
        };

编辑:

 <div class="fade-show-hide" ng-show="loggedInOpened" ng-cloak>
    @Html.Partial("~/Views/Shared/_LoggedInPartial.cshtml")
 </div>

2 个答案:

答案 0 :(得分:1)

您可以使用blur()

例如

<input type="text" ng-enter="doBlur($event)">

脚本

$scope.doBlur = function($event){
    var target = $event.target;
    if (!$scope.loginOpened){
      // do more here, like blur or other things          
      $(target).blur(function() {
       //do what you want here
      });
    }
}

答案 1 :(得分:0)

如果您想隐藏div,可以按照以下步骤操作。

 <div class="fade-show-hide" ng-hide="loggedInOpened" ng-cloak>
        @Html.Partial("~/Views/Shared/_LoggedInPartial.cshtml")
     </div>
     <button type="button" id="btn" ng-click="toggleLoggedIn()">Hide div</button>

$scope.toggleLoggedIn = function () {
            $scope.loggedInOpened = !$scope.loggedInOpened;
            $scope.languagesOpened = false;
            $scope.loginOpened = true;  
        };