ng-show没有显示任何内容

时间:2014-03-19 18:52:37

标签: angularjs ng-show

问题是,当我访问.com /#/ login或任何URL时,它不显示任何错误,但都没有显示login.html文件

这就是我所拥有的:

<div id="content" ng-show></div>

staffApp.config(function($routeProvider, $locationProvider){
    $routeProvider
        .when('/admin',
            {
                templateUrl: '/partials/admin_panel.html',
                controller: 'AdminController',
                access: access.admin
            }
        )

        .when('/',
            {
                templateUrl: '/partials/login.html',
                controller:  'LoginController',
                access: access.anon
            }
        );

    // use the HTML5 History API
    $locationProvider.html5Mode(true);

});

使用访问代码,templateUrls和控制器正确完成。

2 个答案:

答案 0 :(得分:1)

ng-show需要绑定一个变量(例如ng-show =“showContent”,只要它是真实的(showContent = true;),它就会出现。

http://docs.angularjs.org/api/ng/directive/ngShow

现在它没有显示,因为ng-show被绑定为undefined,这是一个假值。

答案 1 :(得分:0)

首先尝试这一点,以确保它显示出你认为应该的样子。

<div id="content" ng-show="true"></div>

一旦你调试了任何不允许硬编码的东西,那么&#34; true&#34;要表明,你可以搞乱变量。

现在这样做......

<div id="content" ng-show="showMe">

In your controller || directive (that has access to the ng-show scope) initialize the variable.

$scope.showMe = false; (this is if you do not want it shown during initial DOM load, true otherwise)

Now in your controller || directive

function iShowThings(param){
  if( conditionIsTrue ){
    $scope.showMe = true; (when you wish to show it)
  }else{
    $scope.showMe = false; (hide it again)
  }
}

or perhaps a click event?
<button ng-click="toggleHiddenThing(showMe)">Toggle Div</button>

Then, in your controller || directive

$scope.toggleHiddenThing = function(showMe){ $scope.showMe = !showMe; }
In this case you would still initialize the showMe variable, then it's current
state would be passed into the function and then flipped with each click event.