【发布时间】:2015-06-29 23:40:03
【问题描述】:
这里的 angularjs 逻辑有问题
我只想在没有用户登录的情况下显示登录链接,并且只显示登录用户的注销链接,但它不能正常工作
我的 HTML
<section ng-controller="a" ng-show="auth = false">
<a href="#/signin" ng-click="signin()"> Sign in </a>
</section>
<section ng-controller="b" ng-show="auth = true">
<a href="#/signout" ng-click="signout()"> Sign out </a>
</section>
登录正常
这是我的控制器
登录控制器
function ($scope, Service){
$scope.auth = true;
$scope.signin = function($event, userID, passwd){
Service.signin(userID,passwd).then(
function (response){
$scope.auth = true;
});
}]).
注销控制器
function ($scope, Service){
$scope.auth = false;
$scope.signout = function($event){
Service.signout().then(
function (response){
$scope.auth = false;
});
}]).
这两个注销和登录链接基本上都在我的主页中。我不想创建很多页面,因此我想互相隐藏。当用户单击登录链接时,它将运行 angularjs 路由器,在这种情况下是 /login,表单还有另一个 templateURL,它将直接附加到主页。一旦用户输入了用户名和密码,用户需要点击提交按钮,这是代码
<form role="form" name="form1">
<label for"userID">UserID</label><input type="text" id="userID" ng-model="userID">
<label for"passwd">Password</label><input type="text" id="passwd" ng-model="passwd">
<button data-ng-click="signin($event,userID,passwd); reload()">Login</button>
reload() 函数会直接刷新页面。我正在使用 $window.location.reload()
【问题讨论】:
-
试试这个
ng-show="auth"和ng-show="!auth" -
不起作用,先生。这个我试过了
-
我认为他们两个都可以是
ng-show="auth"。然后如果该语句为真则显示,如果为假则隐藏 -
你有两个不同的 $scope 使它成为 $root '
-
我在我的服务中使用 http.get 先生
标签: javascript angularjs