title: Angularjs Factory ES6
body: <p>I've been working on a project for a while on my current job and they're using Angulajs for the front-end. Recently I'm trying to implement the ES6 standard. The project uses a Factory to wrap the API services from the backend like this:</p>
  
  <pre><code>'use strict';
  angular.module('products').factory('Products', ['$resource',
    ($resource)=&gt; {
      return $resource('api/products/:productId', {
        productId: '@id'
      },{
        update: {
          method: 'PUT'
        },
        getProductsByType : {
          url: 'api/:schoolIdProduct/products/:Type',
          params: {
            schoolIdProduct: ':schoolIdProduct',
            Type: ':Type'
          },
          isArray: true
        }
      });
    }
  ]);
  </code></pre>
  
  <p>So now right now when we call the Factory from the controller I just add the factory and then call the function like this:</p>
  
  <pre><code>$rootScope.supplies = Products.getProducts({
    schoolIdProduct: schoolId,
    Type: 'Supplies'
  });
  </code></pre>
  
  <p>So when I try to use the arrow function and <code>then()</code> to wait for the response the browser console tells me that is not a function. How do I change my code to use the ES6 standard and get something like this?</p>
  
  <pre><code>    Products.getProducts({
        schoolIdProduct: schoolId,
        Type: 'Supplies'
      }).then( (response) =&gt;{
        $rootScope.supplies = response;
      });
  </code></pre>