[英]AngularJS ng-click not displaying ng-show message
I have searched for an answer to my problem and not sure why my ng-click is not firing the ng-show message for me. 我一直在寻找问题的答案,但不确定为什么我的ng-click不能为我触发ng-show消息。
I have my controller function: 我有控制器功能:
$scope.showLogoutMessage = function() {
$scope.logoutmsg = true;
};
My Login page html: 我的登录页面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>
Then I fire this ng-show from a different jsp page: 然后,我从另一个jsp页面触发此ng-show:
<li><a ng-controller="LoginController" id="logout" href="javascript;;"
ng-click="showLogoutMessage()">Log Out</a></li>
I have logged out messages in my controller and the value 'logoutmsg' is being set fine but just won't display my message for some reason. 我已经在控制器中注销了消息,并且已将值'logoutmsg'设置为正常,但由于某种原因不会显示我的消息。 Anyone have any ideas?
有人有想法么?
Is the first code that you have written is in same controller (LoginController). 是您编写的第一个代码在同一控制器(LoginController)中。 if not
如果不
give a name to that controller 给那个控制器起个名字
<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>
then 然后
$scope.showLogoutMessage = function() {
angular.element(document.getElementById('message')).scope().logoutmsg = true;
};
if this works then fine else u can try adding one more line in above function 如果这可以正常工作,否则您可以尝试在上述功能中再添加一行
angular.element(document.getElementById('message')).scope().$apply()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.