title: How can I get the response of a POST request using Angular JS?
body: <p>I am  using node, express, mongoose for backend and angular js for front-end. I am sending a post request using a form.</p>
  
  <pre><code>&lt;div class="alert alert-success" ng-show="success"&gt;
    {{success}}
  &lt;/div&gt;
  
  &lt;div class="alert alert-danger" ng-show="error"&gt;
    {{error}}
  &lt;/div&gt;
  
    &lt;form id="newCategory" ng-submit="submit()"&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-4"&gt;
          {{mySubmit}}
          &lt;div class="form-group"&gt;
            &lt;input id="name" name="name" type="text"
              placeholder="Name" class="form-control input-md"
              ng-model="catName"&gt;
          &lt;/div&gt;&lt;!-- ./form-group --&gt;
  
        &lt;/div&gt;&lt;!-- ./col --&gt;
  
        &lt;div class="form-group"&gt;
         &lt;input type="submit" name="submit" value="submit" class="btn btn-primary"&gt;
        &lt;/div&gt;&lt;!-- ./form-group --&gt;
  
      &lt;/div&gt;&lt;!-- ./row --&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>Its controller:</p>
  
  <pre><code>  fetchModule.controller('CatsNewCtrl', ['$scope', '$rootScope', 'Request',
      function($scope, $rootScope, Request) {
        // Root Scope
        $rootScope.heading  = 'Categories';
        $rootScope.heading2 = 'new';
        $rootScope.newLink  = undefined;
  
        $scope.catName = "";
        $scope.submit = function() {
          Request.post('/category', { name  : $scope.catName })
            .then(function(data) {
              $scope.success = data.msg;
            })
            .catch(function(status) {
              $scope.error = "Error: " + status;
            });
          return false;
        };
    }]);
  </code></pre>
  
  <p>Result is nothing, I don't know where am I going wrong! This service is working fine in fact I was able to console log the result but I am unable to set it on scope.</p>
  
  <pre><code>(function() {
    let fetchModule = angular.module('fetchModule', []);
  
    /**
     * A Service for Requests.
     */
    fetchModule.service('Request', ['$http', function($http) {
      /**
       * Get's content of a specific URL.
       * @param {String} url - URL to GET.
       * @return {Promise} Promise resolves with contents or rejects with an error.
       */
      this.get = function(url) {
        // Promise
        return new Promise((resolve, reject) =&gt; {
          $http.get(url)
            .success(result =&gt; {
              resolve(result);
            })
            .error((err, status) =&gt; {
              reject(err);
            });
        });
      };
  
  /**
   * Get's content of a specific URL.
   * @param {String} url - URL to GET.
   * @param {String} data - Data to post.
   * @return {Promise} Promise resolves with contents or rejects with an error.
   */
  this.post = function(url, data) {
    // Promise
    return new Promise((resolve, reject) =&gt; {
      $http.post(url, data)
        .success((data, status, headers, config) =&gt; {
          resolve(data);
        })
        .error((data, status, headers, config) =&gt; {
          resolve(status);
        });
    });
  };
  </code></pre>
  
  <p>Please help I am just an angular starter.</p>