2017-05-20 1 views
1

로그인 폼이 있습니다. 로그인하면 페이지에 사용자 이름이 표시됩니다. 이름에 마우스가 있으면 로그 아웃 링크가 표시됩니다. 내가 문서를 클릭하면 로그 아웃 링크를 숨길 필요가있다. 나는 마우스를 움직였다. 내가 문서를 클릭하면 그러나angularjs에서 documet.click의 요소를 숨기기

<a class="usrname" ng-mouseover="lgout='false'" ng-init="lgout='true'">Mr. Admin</a> 
         <br /> 
<a id="A4" class="logout" href="LogIn.aspx" style="float: right;" ng-hide="lgout">Logout</a> 

내 스크립트를 숨길 수 없습니다

$(document).click(function() { 
        var scope = angular.element($("lgout")).scope(); 
        scope.$apply(function(){ 
        scope.selectValue = 'true'; 
      }); 
     }); 

답변

2

이 줄을 변경해보십시오 :이와

var scope = angular.element($("lgout")).scope(); 

:

var scope = angular.element($("#A4")).scope(); 

주 : 전역 메서드에서 범위를 찾는 대신 컨트롤러에서 범위를 찾는 것이 좋습니다.

var app = angular.module("myApp", []); 
app.controller("test", function ($scope) { 
    $scope.lgout = false; 

    $(document).click(function() { 
     $scope.$apply(function() { 
      $scope.lgout = false; 
     }); 
    }); 
}); 
관련 문제