Like @dfsq said you need an ng-view to post your new view there. Of course, if you add your ng-view to the index, you will see the contents of the index and the house. The solution here is to create two partial views, one for log authentication and one for home. The index file should contain only ng-view and those elements that you want to keep constant throughout the application (menu, footer ...)
Here is the code of what I'm saying: index.html
<html ng-app='myApp'> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script> <script src='test.js' type="text/javascript"></script> </head> <body > <div ng-view></div> <script src='test.js' type="text/javascript"></script> </body> </html>
New route configuration
applog.config([ '$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { $routeProvider.when('/home', { templateUrl : 'home.html', controller : 'HomeController' }) $routeProvider.when('/', { templateUrl : 'auth.html', controller : 'LoginController' }).otherwise({ redirectTo : 'index.html' }); //$locationProvider.html5Mode(true); //Remove the '#' from URL. } ]);
and enter your auth.html login code
<div id='content' 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> <input type="username" class="form-control" ng-model="user.name" required> </span> </br> </br> <span><b>Password :</b> <input type="password" class="form-control" ng-model="user.password" required> </span> <br><br> <button class="btn btn-lg btn-primary btn-block" type="submit"> <b>Sign in</b> </button> </form> </div> </div>
Keep in mind that if you put test.js script in the index, this will be the whole application.
Hope this helps
source share