Monday 5 June 2017

Can't get elements from json response

I can't get to see on my table elements from my json response, received from get method. Here it is my html:

<div ng-controller="EstadisticaController" data-ng-init="init()">
  <div class="jumbotron text-center">
      <h1>Historico</h1>
      <div class="table-responsive">
        <table class="table table-striped">
          <tr ng-repeat="a in acontecimiento">
            <td></td>
          </tr>
        </table>
      </div>
  </div>
</div>

the controller:

angular.module('EstadisticaCtrl', ['AcontecimientoService'])
  .controller('EstadisticaController', function($scope, Acontecimiento) {
    $scope.init = function(res) {
      Acontecimiento.get($scope.acontecimiento);
    };
  });

the service:

angular.module('AcontecimientoService', [])
  .factory('Acontecimiento', function($http) {
    return {
        // call to get all nerds
        get : function() {
            return $http.get('/api/acontecimiento');
        }
    }
});

and finally the get method:

var Acontecimiento = require('./models/acontecimiento');
 module.exports = function(app) {
   app.get('/api/acontecimiento', function(req, res) {
       Acontecimiento.find(function(err, acontecimiento) {
           if (err)
               res.send(err);
           res.json(acontecimiento); // return all nerds in JSON format
       });
   });
}



via Fjallbacka

No comments:

Post a Comment