在angularjs中从一个页面导航到另一个页面

时间:2014-05-07 13:34:48

标签: angularjs

我知道我已经问了同样的问题,但我无法解决这个问题。我正试图从登录页面导航到下一页......

的login.html

<body>
<div id='content' ng-app='myApp' ng-controller='LoginController'>
<div class="container">
<form class="form-signin" role="form" ng-submit="login()">
   <h3 class="form-signin-heading">Login Form</h3>
   <span><b>Username :</b>&nbsp;
    <input type="username" class="form-control" ng-model="user.name"  required>
   </span>
   </br></br>
   <span><b>Password :</b>&nbsp;&nbsp;
     <input type="password" class="form-control" ng-model="user.password" required>
   </span>
   <label class="checkbox">
    <input type="checkbox" value="remember-me"> Remember me
    </label>
   <button class="btn btn-lg btn-primary btn-block"  type="submit" >           
   <b>Sign in</b></button>       
  </form>
  </div> <!-- /container -->
  </div>   
 </body>

我的app文件是

'use strict';
//Define Routing for app

var applog = angular.module('myApp',['ngRoute']);
applog.config(['$routeProvider', '$locationProvider',
function($routeProvider,$locationProvider) {
 $routeProvider
  .when('/login', {
     templateUrl: 'html/navAng.html',
     controller: 'LoginController'
   })    
  .otherwise({
    redirectTo: 'html/navAng.html'
   });
   $locationProvider.html5Mode(true); //Remove the '#' from URL.
  }]);

,控制器是

 applog.controller("LoginController", function($scope, $location){     


$scope.login=function()
   {

    var username=$scope.user.name;
    var password=$scope.user.password;
    if(username=="admin" && password=="admin")
    {

        $location.path( "html/navAng.html" );
    }
    else
    {
        $scope.message="Error";
        $scope.messagecolor="alert alert-danger";
    }
  }

});

现在当我点击登录按钮时,url正在生成,但它只是更改了url选项卡中的url,没有任何反应,即页面没有刷新或导航到下一页....有人可以帮助plz ...

1 个答案:

答案 0 :(得分:2)

只需输入不带.html的路径,就像这样

$location.path( "/login" );