2015-01-24 2 views
1

내 문제에 대한 답변을 검색했으며 ng-click이 ng-show 메시지를 보내지 않는 이유를 모르겠습니다.AngularJS ng-click가 ng-show 메시지를 표시하지 않음

나는 내 컨트롤러 기능이 있습니다

$scope.showLogoutMessage = function() { 
    $scope.logoutmsg = true; 
}; 

내 로그인 페이지 HTML :

<input id="j_password" type="password" name="j_password" class="form-control input-lg" placeholder="Password" ng-model="loginData.j_password" required /> 
<small style="color:red;" class="error" ng-show="logoutmsg"> 
    You have been logged out. 
</small> 

그럼 난 다른 JSP 페이지에서이 NG-쇼를 발사 :

<li><a ng-controller="LoginController" id="logout" href="javascript;;" 
ng-click="showLogoutMessage()">Log Out</a></li> 

I 내 컨트롤러에 메시지를 로그 아웃했는데 'logoutmsg'값이 잘 설정되어 있지만 일부 메시지가 표시되지 않습니다. 아들. 누구든지 아이디어가 있습니까?

+0

는 위의 함수에 하나 더 줄을 추가 시도 할 수 있습니다 그 함수가 클릭 할 때 반드시 호출 되는지요? 왜 당신은 href = javascript ;;를 사용하고 있습니까? ng-click은 이미 링크의 기본 동작을 차단합니다. –

+0

전체 코드를 게시 하시겠습니까? 버튼 클릭이 다른 컨트롤러에 속하고 다른 메시지가 다른 사람에게 속한 것 같습니다. –

+0

다른 JSP 페이지에 있다면 다른 범위가 될 것입니다. –

답변

0

작성한 첫 번째 코드가 동일한 컨트롤러 (LoginController)에 있습니까? 이 후 다른 잘 작동하는 경우

는 해당 컨트롤러

<input id="j_password" type="password" name="j_password" class="form-control input-lg" placeholder="Password" ng-model="loginData.j_password" required /> 
    <div id='message' ng-controller='MesssageCtrl' > 
    <small style="color:red;" class="error" ng-show="logoutmsg"> 
     You have been logged out. 
    </small> </div> 
다음

$scope.showLogoutMessage = function() { 
    angular.element(document.getElementById('message')).scope().logoutmsg = true; 
}; 

에 이름을 지정하지 않을 경우 유

angular.element(document.getElementById('message')).scope().$apply() 
+0

'$ document'는 jQlite 객체이고'getElementById()'메소드가 없습니다. 특정 elemnt 범위를 찾는 것보다 더 많은 테스트 가능한 접근 방법이 있습니다. – charlietfl

+0

미안하지만 실수를 잘못 입력했습니다. @charlietfl에게 알려 주셔서 감사합니다. – praveenraj

관련 문제