Ng Show仅适用于刷新

时间:2015-08-06 19:38:27

标签: javascript jquery angularjs angularjs-scope angular-material

我正在处理的方案是,当用户登录时,他们会看到一个单独的导航选项和按钮列表,而不是未登录的用户。

为此,我使用NgShow来显示/隐藏这些元素。我面临的问题是,在我对页面进行刷新之前,这些元素不会显示/隐藏。

有什么建议吗? 谢谢

CTRL

angular.module('core').controller('HeaderController', ['$scope', '$mdSidenav', 'Authentication', 'Users', 'Menus',
function($scope, $mdSidenav, Authentication, Users, Menus) {
    $scope.authentication = Authentication;
    $scope.user = Authentication.user;
    $scope.isCollapsed = false;

    $scope.toggleCollapsibleMenu = function() {
        $scope.isCollapsed = !$scope.isCollapsed;
    };

    // Collapsing the menu after navigation
    $scope.$on('$stateChangeSuccess', function() {
        $scope.isCollapsed = false;
    });

    $scope.toggleSidenav = function(menuId) {
            $mdSidenav('left').toggle();
            };
}

])

HTML / VIEW

<md-button aria-label="Search" data-ng-click="showSearch = !showSearch" data-ng-show="user">
    <ng-md-icon style="fill:#fff;" icon="search"></ng-md-icon>
  </md-button>

  <md-button data-ng-show="!user" aria-label="Sign In" data-ng-href="#!/signin">
    <ng-md-icon style="fill:#fff;" icon="login"></ng-md-icon><span style="padding-left:10px;color:#fff;">Sign In</span>
  </md-button>
  <md-button data-ng-show="!user" aria-label="Sign Up" data-ng-href="#!/signup">
    <ng-md-icon style="fill:#fff;" icon="local_florist"></ng-md-icon><span style="padding-left:10px;color:#fff;">Sign Up</span>
  </md-button>

0 个答案:

没有答案