表不显示数据

时间:2017-06-02 15:22:44

标签: angularjs node.js

我的网站开发存在一些问题。它是MEAN堆栈,我将在表格中显示数据

路由node.js



var Property = mongoose.model('Property');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId; //Have also tried Schema.Types.ObjectId, mongoose.ObjectId

// Property Routing Management

router.get('/property', function(req, res, next) {
  Property.find({}, function(err, properties) {
    if (err) {
      return next(err);
    }
    return res.json(properties);
  })
});




角度控制器



angular.module('MetronicApp').controller('EditPropertyController', [
        '$scope',         
        's_property',
        '$state', 
        '$location',
        function($scope, s_property, $state, $location) {            
            s_property.getAllProperties();
            $scope.properties = s_property.all_properties;

}]);




服务



angular.module('MetronicApp')
  .factory('s_property', [
    '$http',
    '$window',
    's_auth',
    function($http, $window, s_auth) {
      var service = {
        all_properties: [],
        current_property: {}
      };
      service.getAllProperties = function() {
        return $http.get('/api/v1/property').then(function(res, err) {
          service.all_properties = res.data;          
          return res.data;
        })
      }
      return service;
    }
  ]);




HTML



<tr class="odd gradeX" ng-repeat="property in properties">
  <td ng-bind="property.propertyAddress"></td>
  <td ng-bind="property.propertyCity"></td>
  <td ng-bind="property.status"></td>
  <td class="center" ng-bind="property.joinedDate"></td>
  <td ng-bind="property.user"></td>
</tr>
&#13;
&#13;
&#13;

MongoDB中存在集合和文档,但我的HTML表格不显示数据。 我很感激你的回答。

1 个答案:

答案 0 :(得分:0)

你做错了:

s_property.getAllProperties().then(function(allProps) {
  $scope.properties = s_property.all_properties;
  // alternatively, this. they would give you the same results
  // $scope.properties = allProps;
});

在分配$scope变量properties之前,您没有等待承诺解决。你是在尝试吃披萨之前吃的。