title: i want to create a service that does the login functionality?
body: <p>here is my app.js in which i have create a service which should check that if this particular username and password fills in login should be done and page should be redirected to home.html
  i am not able to get how to call that particular service into the controller and whether i have created the service correctly.</p>
  
  <p>i also need to check that both the fields should not be empty is they gets empty submit button should gets disabled.</p>
  
  <pre><code> app.js 
  
      // create angular app
      var validationApp = angular.module('validationApp',['ngRoute']);
      validationApp.config(
          function($routeProvider) {
              $routeProvider
                  .when('/', {
                      templateUrl: 'main.html',
                      controller: 'mainController'
                  })
                  .when('/home', {
                      templateUrl: 'home.html',
                      controller: 'mainController'
                  })
                  .otherwise({
                      redirectTo: '/main.html'
                  });
          });
  
      validationApp.service('loginservice',function()
      {
          this.login = function($scope,$location){
              var username = $scope.user.email;
              var password = $scope.user.password;
              if(username == "ank@gmail.com" &amp;&amp; password=="1234")
              {
                  if ($scope.userForm.$valid) {
                      alert('thank you for submitting your form');
                      $location.path("/home");
  
                  }
  
              }
              else
              {
                  alert("invalid username and password");
              }
          }
      });
  
  
      // create angular controller
      validationApp.controller('mainController', function($scope,loginservice) {
  
      $scope.dologin = loginservice.login();
  
  
      });
  </code></pre>
  
  <p>//here is my index.html page</p>
  
  <pre><code>&lt;body&gt;
  &lt;div  ng-app="validationApp"&gt;
     &lt;ng-view&gt;&lt;/ng-view&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>//here is my main.html page</p>
  
  <pre><code>main.html
  
  &lt;div class="container"&gt;
      &lt;div class="row"&gt;
          &lt;div&gt;
              &lt;form name="userForm" method="post" ng-submit="dologin()" novalidate&gt;
                  &lt;h1&gt;Login Form&lt;/h1&gt;
                  &lt;div class="form-group" ng-class="{ 'has-error' : userForm.email.$invalid &amp;&amp; !userForm.email.$pristine }"&gt;
                      &lt;label&gt;Email&lt;/label&gt;
                      &lt;input type="email" name="email" class="form-control" ng-model="user.email" value="ank@gmail.com"&gt;
                      &lt;p ng-show="userForm.email.$invalid &amp;&amp; !userForm.email.$pristine" class="help-block"&gt;Enter a valid email.&lt;/p&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group" ng-class="{ 'has-error' : userForm.password.$invalid &amp;&amp; !userForm.password.$pristine }"&gt;
                      &lt;label&gt;Password&lt;/label&gt;
                      &lt;input type="password" name="password" class="form-control" ng-model="user.password" value="1234"&gt;
                      &lt;p ng-show="userForm.password.$invalid &amp;&amp; !userForm.password.$pristine" class="help-block"&gt;Enter a valid password.&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;label&gt;Click me to toggle: &lt;input type="checkbox" ng-model="checked"&gt;&lt;/label&gt;&lt;br/&gt;
                  &lt;button ng-model="button" ng-disabled="checked"&gt;Button&lt;/button&gt;
                  &lt;button type="submit" class="btn btn-primary" ng-disabled="userForm.$invalid" &gt;Submit&lt;/button&gt;
  
              &lt;/form&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>