0

问题是当我访问 .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 和控制器。

4

2 回答 2

1

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

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

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

于 2014-03-19T18:57:08.810 回答
0

首先尝试此操作,以确保它按您认为的那样显示。

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

一旦你调试了任何不允许硬编码的 ngShow="true" 显示的东西,你就可以弄乱一个变量。

现在这样做...

<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.
于 2015-01-14T20:40:32.093 回答