我已经搜索了我的问题的答案,但不确定为什么我的 ng-click 没有为我触发 ng-show 消息。
我有我的 Controller 功能:
$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-show:
<li><a ng-controller="LoginController" id="logout" href="javascript;;"
ng-click="showLogoutMessage()">Log Out</a></li>
我已在 Controller 中注销消息,并且值“logoutmsg”设置得很好,但由于某种原因不会显示我的消息。大家有什么想法吗?
最佳答案
您编写的第一个代码是在同一个 Controller (LoginController)中吗?如果没有
为该 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>
然后
$scope.showLogoutMessage = function() {
angular.element(document.getElementById('message')).scope().logoutmsg = true;
};
如果这有效,那么就可以了,否则你可以尝试在上面的函数中再添加一行
angular.element(document.getElementById('message')).scope().$apply()
关于javascript - AngularJS ng-click 不显示 ng-show 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28127535/