angularjs的退出方法?

时间:2014-05-14 16:27:09

标签: angularjs angularjs-directive

我已经开始学习angularjs两天了,有很多新概念对我来说很新,我正在为我的最终项目构建一个测试项目,测试到目前为止所有新的不同的东西,
我停留在注销,我已经在登录控制器中实现了ng-if指令,它运行得很好我已经测试了登录请求的成功方法,但我想将我的注销html移动到导航栏中index.html,所以我不知道在哪里把我的逻辑用于测试cookie? 这是我的index.html

    <div ng-controller="HomeController">
    <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/">Brand</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="/Register">Register</a></li>
                    <li><a href="/Login">Login</a></li>
                    <li><a href="/Articles">Articles</a></li>
                    <li ng-if ="isAuth" ng-click="LogOut()"><a href="/Logout">LogOut</a></li>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>
</div>
<div data-ng-view=""></div>

的HomeController

app.controller('HomeController', function ($scope, Auth) {
    $scope.isAuth = Auth.IsAuth;
 });

验证服务

app.service('Auth', function ($cookieStore) {
var auth = function myfunction() {
    if ($cookieStore.get('token')) {
        return true;
    }else{
        return false;
    }
}
return{
    isAuth : auth()
    }
});

0 个答案:

没有答案