title: Sails data from service to controller
body: <p>I'm starting with sails js and node more generally .</p>
  
  <p>I'm trying to use the regular way of implementing services in sails to pass data in my controller.</p>
  
  <p>for example, I've a dashboard view, called dashboard.ejs</p>
  
  <p>my view is correctly routed and everything.</p>
  
  <p>But the regular ways of passing data from service wasn't working at all, and I ended up with that to make it work, which seems to be very unappropriate:</p>
  
  <p>my CountService.js:</p>
  
  <pre><code>module.exports = {
  
  RoomCount: function(req, res, cb, tab)
  {
  Room.count().exec(function(err, roomfound){
      tab.push(roomfound);
      cb(req, res, tab);
  });
  },
  VenteCount: function(req, res, cb, tab)
  {
  Vente.count().exec(function(err, ventefound){
      tab.push(ventefound);
      cb(req, res, tab);
  });
  },
  LotCount: function(req, res, cb, tab)
  {
  Lot.count().exec(function(err, lotfound){
      tab.push(lotfound);
      cb(req, res, tab);
  });
  }
  };   
  </code></pre>
  
  <p>My DashboardController.js</p>
  
  <pre><code>module.exports = {
  
  
  dashboard: function(req, res, next)
  {
  var tab = []
  var end_dashboard = function(req, res, tab){
      res.view('dashboard', {
              roomCount: tab[0],
              venteCount: tab[1],
      lotCount: tab[2]
          });
  };
  var callbacklot = function(req, res, tab){
      end_dashboard(req, res, tab);
  };
  var callbackvente = function(req, res, tab){
      CountService.LotCount(req, res, callbacklot, tab);
  };
  var callbackroom = function(req, res, tab){
      CountService.VenteCount(req, res, callbackvente, tab);
  };
  CountService.RoomCount(req, res, callbackroom, tab);
  },
  };
  </code></pre>
  
  <p>And then I can call the VenteCount etc values in my view ejs</p>
  
  <p>The regular way was giving a value = undefined</p>
  
  <p>I think I was wrong in the res() or next() part so I ended like that but it makes the service thing very complicated...</p>
  
  <p>Thanks a lot for your help</p>