我的网站开发存在一些问题。它是MEAN堆栈,我将在表格中显示数据
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;
}
]);

<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;
MongoDB中存在集合和文档,但我的HTML表格不显示数据。 我很感激你的回答。
答案 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
之前,您没有等待承诺解决。你是在尝试吃披萨之前吃的。