Ezhil
Ezhil

Reputation: 261

navigation from one page to another in angularjs

I know i have already asked the same question but i am getting nowhere with this problem..I am trying to navigate from login page to next page...

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>

my app file is

'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.
  }]);

and the controller is

 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";
    }
  }

});

now when i click on the login button the url is getting generated but it just changes the url in the url tab and nothing happens i.e the page is not getting refreshed or navigating to the next page....can someone help plz...

Upvotes: 0

Views: 7671

Answers (1)

z.a.
z.a.

Reputation: 2777

just enter the path not with .html, like this

$location.path( "/login" );

Upvotes: 2

Related Questions