AngularJS - ng-show无法按预期工作

时间:2015-05-15 10:31:26

标签: javascript angularjs passport.js

我正在尝试隐藏<a>个标签,然后在我登录时使用isLoggedIn()功能显示它们,但无论<a>标记是什么

HTML(pool-details.html)

<header class="hero-unit" id="banner" ng-include="'components/header/header.html'"></header>

<div ng-include="'components/navbar/navbar.html'"></div>

<div class="container"> <hr>
    <div class="col-md-3 left-col-3">  
        <div ng-include="'../components/sidebar/sidebar.html'"></div>
    </div>

    <div class="col-md-5">
        <div class="details-pic">
            <img class="pool-details-pic" ng-src="{{ pool.picture }}"/>
        </div>
    </div>

    <div class="col-md-4">
        <h3 class="details-name">{{ pool.name }}</h3>
        <p class="details-info">Varenummer: {{ pool.number }}</p>
        <p class="details-info">Lager status: {{ pool.inStock }}</p>
        <p class="details-info">Dimensioner: {{ pool.width }}m x {{ pool.length }}m x {{ pool.height }}m</p>
        <hr>
        <p class="details-info">{{ pool.info }}</p>
    </div>
    <div class="col-md-12">
        <a ng-show="'isLoggedIn()'" ng-click="deleteProduct(pool)" class="delete-product">Slet</a>
        <a ng-show="'isLoggedIn()'" ng-click="editProduct(pool)" class="edit-product">Opdater</a>
    </div>

</div>

<footer class="footer" ng-include="'components/footer/footer.html'"></footer>

CONTROLLER(pool-details.controller.js)

'use strict';

angular.module('welldanaJavascriptApp')
    .controller('poolDetailsCtrl', function ($scope, $stateParams, $state, poolService, Auth) {

        $scope.pool = {};
        poolService.find($stateParams.poolId, function(pool) {
             $scope.pool = pool;
        });

        $scope.deleteProduct = function(product){
            poolService.delete(product._id, function(){
                $state.go('pools');   
            });
        };
});

我无法理解为什么<a>标签仍在显示,但我还没有登录。我正在使用Passport插件进行Angular fullstack应用程序。

2 个答案:

答案 0 :(得分:2)

ng-show="'isLoggedIn()'"

计算&#39; isLoggedIn()&#39;字符串,它将始终为true,您应该重构为ng-show="isLoggedIn()"

答案 1 :(得分:0)

好的,我设法解决了我的问题。我的道歉,这是一个简单的菜鸟错误。

<强>解决方案

我错过了$scope.isLoggedIn()

我只是将其添加到控制器:

$scope.isLoggedIn = function(){
    return Auth.isLoggedIn();
}

只需返回Auth.isLoggedIn()即可将此值实际添加到我的范围,从而能够在HTML中进行检查。