title: AngularJS : get object by id from factory
body: <p>I have a <code>factory</code> to get an array with all my clientes from the database.
  Then i need to filter this array by the person <code>id</code> and show only it's data in a single page.</p>
  
  <p>I have a working code already, but it's only inside a <code>controller</code> and I want to use it with a <code>factory</code> and a <code>directive</code> since i'm no longer using <code>ng-controller</code> and this <code>factory</code> already make a call to other pages where I need to show client data.</p>
  
  <p>This is what i tried to do with my <code>factory</code>:</p>
  
  <p><strong><em>app.js</em></strong></p>
  
  <pre><code>app.factory('mainFactory', function($http){
  
      var getCliente = function($scope) {
          return $http.get("scripts/php/db.php?action=get_cliente")
          .success( function(data) {
              return data;
          })
          .error(function(data) {
          });
      };
  
      var getDetCliente = function($scope,$routeParams) {
          getCliente();
          var mycli = data;
          var myid = $routeParams.id;
          for (var d = 0, len = mycli.length; d &lt; len; d += 1) {
              if (mycli[d].id === myid) {
                  return mycli[d];
              }
          }
          return mycli;
      };
  
      return {
          getCliente: getCliente,
          getDetCliente: getDetCliente
      }
  });
  
  app.directive('detClienteTable', function (mainFactory) {
      return {
          restrict: "A",
          templateUrl: "content/view/det_cliente_table.html",
          link: function($scope) {
              mainFactory.getDetCliente().then(function(mycli) {
                  $scope.pagedCliente = mycli;
              })
          }
      }
  });
  </code></pre>
  
  <p><strong><em>detClient.html</em></strong></p>
  
  <pre><code>&lt;p&gt;{{pagedCliente.name}}&lt;/p&gt;
  &lt;p&gt;{{pagedCliente.tel}}&lt;/p&gt;
  &lt;p&gt;{{pagedCliente.email}}&lt;/p&gt;
  [...more code...]
  </code></pre>
  
  <p>The problem is, I'm not able to get any data to show in the page, and also, i have no errors in my console.</p>
  
  <p>What may be wrong? <br />
  Keep in mind I'm learning AngularJS.</p>