title: How to redirect a page to another using AngularJS in ExpressJS
body: <p>This is the login page </p>
  
  <pre><code>        &lt;!DOCTYPE html&gt;
          &lt;html ng-app="myApp"&gt;
          &lt;head&gt;
          &lt;!--&lt;script src="controllers/logincontroller"&gt;&lt;/script&gt; --&gt;     
  
          &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"&gt;
  
          &lt;!-- Optional theme --&gt;
          &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"&gt;
  
              &lt;title&gt;Login Page&lt;/title&gt;
          &lt;/head&gt;
          &lt;body&gt;
  
          &lt;div class="container" ng-controller="loginctrl"&gt;
          &lt;h1&gt;Login Page&lt;/h1&gt;
          &lt;label&gt;UserName&lt;/label&gt;&lt;input class="form-control" ng-model="user.name"&gt;&lt;br&gt;&lt;br&gt;
          &lt;label&gt;Password&lt;/label&gt;&lt;input class="form-control" ng-model="user.password"&gt;&lt;br&gt;&lt;br&gt;
          &lt;button class="btn btn-primary" ng-click="login()" &gt;Login&lt;/button&gt;
          &lt;/div&gt;
  
          &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"&gt;&lt;/script&gt;
          &lt;script src="controllers/logincontroller.js"&gt;&lt;/script&gt;
          &lt;script src="angularjs/angular.js"&gt;&lt;/script&gt;
          &lt;script src="angular-route/angular-route.js"&gt;&lt;/script&gt;
          &lt;/body&gt;
          &lt;/html&gt;                 
  
     This is Controller page
  
          var myapp = angular.module('myApp', ['ngRoute']);
  
          myapp.config(["$routeProvider", function($routeProvider) {
              $routeProvider
              .when('/', {
                  controller: 'loginctrl',
                  templateUrl: 'login.html'
              })
              .when('/addusers', {
                  controller: 'addusersctrl',
                  templateUrl: 'addusers.html'
              })
              .otherwise({
                  redirectTo: '/'
              });            
          }]);
  
          myapp.controller('loginctrl',['$scope', '$route', '$routeParams', '$location',function($scope,$http,$location){
              console.log("im a controller");            
  
              $scope.login = function() {
                  //console.log($scope.user);
  
                  // $http.post('/login',$scope.user).success(function(response){
                  //  console.log(response);
                  // });
  
                  $http({
                        method: 'post',
                        url: '/login',
                        data: $scope.user 
                      }).then(function successCallback(response) {
                          // this callback will be called asynchronously
                          // when the response is available
  
                          console.log(response.data);
                          //$window.location.href = 'addusers.html';
                           $location.path("/addusers");
                      }, function errorCallback(response) {
  
                          console.log(response.data);
                          // called asynchronously if an error occurs
                          // or server returns response with an error status.
                      });            
              };
          }]);            
  
          myapp.controller('addusersctrl',['$scope','$http',function($scope,$http){
              console.log("im a controller");           
  
              $scope.login = function() {
                  //console.log($scope.user);
  
                  // $http.post('/login',$scope.user).success(function(response){
                  //  console.log(response);
                  // });
  
                  $http({
                        method: 'post',
                        url: '/login',
                        data: $scope.user 
                      }).then(function successCallback(response) {
                          // this callback will be called asynchronously
                          // when the response is available
  
                          console.log(response.data);
                          //$window.location.href = 'addusers.html';
  
                      }, function errorCallback(response) {
  
                          console.log(response.data);
                          // called asynchronously if an error occurs
                          // or server returns response with an error status.
                      });            
              };
          }]);
  </code></pre>
  
  <p>Whenever I am trying to run this code I am getting</p>
  
  <blockquote>
    <p>Angular.js error
        angular.js:38 Uncaught Error: [$injector:modulerr] <a href="http://errors.angularjs.org/1.6.1/" rel="nofollow noreferrer">http://errors.angularjs.org/1.6.1/</a>$injector/modulerr?p0=myApp&amp;p1=Error%3A%2…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.1%2Fangular.min.js%3A21%3A332)</p>
  </blockquote>