title: How to connect to backend server using API in angularjs ionic
body: <p>I have been trying to connect to the backend server using $http requests in ionic angularjs. I want to register a user using the API. Can someone tell me whats wrong with my code? This is my controller.js</p>
  
  <pre><code>angular.module('app.Auth', [])
  
  .factory('Auth', ['$q', '$http', '$localStorage', 'URL', function($q, $http, $localStorage, URL) {
  
  return {
      register: function(data, success, error) {
          $http.post(URL.api + 'register', data).success(success).error(error)
      }
  };
  }])
  .controller('SignupCtrl', function($scope, $rootScope, $timeout, $stateParams, ionicMaterialInk,Auth,$localStorage,$state,Auth,URL) {
  
  $scope.signupError = function(msg){
      if(msg.status == false){
          $scope.errors = msg.errors;
      }else{
          $scope.errors = ['Error accessing API.'];
      }
  };
  
  
  $scope.signupSuccess = function(response){
      if(response.status==false){
          $scope.errors = response.errors;
      }else{
          alert("success!");
      }
  
  };
  
  $scope.user = {
      firstname:'',
      middlename:'',
      lastname:'',
      password: '',
      email: ''
  };
  
  $scope.signupEmail = function(){
      Auth.register($scope.user,$scope.signupSuccess,$scope.signupError);
  };
  });
  </code></pre>
  
  <p>and this is my signup.html</p>
  
  <pre><code>&lt;ion-view view-title="Sign Up" name="signup"&gt;
  &lt;ion-content&gt;
    &lt;div class="list"&gt;
     &lt;div ng-if="errors.length &gt; 0" class="error_bg" ng-repeat="error in errors"&gt;
              &lt;p class="error" ng-bind="error"&gt;&lt;/p&gt;
          &lt;/div&gt;
      &lt;label class="item item-input item-floating-label"&gt;
          &lt;span class="input-label"&gt;First Name&lt;/span&gt;
          &lt;input type="text" placeholder="First Name" style="color:purple; font-size:18px" ng-model="user.firstname"&gt;
      &lt;/label&gt;
      &lt;label class="item item-input item-floating-label"&gt;
          &lt;span class="input-label"&gt;Middle Name&lt;/span&gt;
          &lt;input type="text" placeholder="Middle Name" style="color:purple; font-size:18px" ng-model="user.middlename"&gt;
      &lt;/label&gt;
      &lt;label class="item item-input item-floating-label"&gt;
          &lt;span class="input-label"&gt;Last Name&lt;/span&gt;
          &lt;input type="text" placeholder="Last Name" style="color:purple; font-size:18px" ng-model="user.lastname"&gt;
      &lt;/label&gt;
      &lt;label class="item item-input item-floating-label"&gt;
          &lt;span class="input-label"&gt;Email Address&lt;/span&gt;
          &lt;input type="text" placeholder="Email Address" style="color:purple; font-size:18px" ng-model="user.email"&gt;
      &lt;/label&gt;
      &lt;label class="item item-input item-floating-label"&gt;
          &lt;span class="input-label"&gt;Password&lt;/span&gt;
          &lt;input type="password" placeholder="Password" style="color:purple; font-size:18px" ng-model="user.password"&gt;
      &lt;/label&gt;
      &lt;/div&gt;
    &lt;button class="button button-block button-royal" style="background-color:blue" ng-click="signupEmail()"&gt;Continue&lt;/button&gt;
  </code></pre>
  
  <p>
  </p>