我有一个使用 mongoose 访问 mongodb 的函数,数据库调用有效并出现在控制台中,但它没有按应有的方式返回该数组。想不通为什么。
exports.getPrices = function() {
return Price.find().exec(function (err, docs) {
if (err) {
return err;
}
console.log(docs);
return docs;
});
};
来自服务的调用
angular.module('core')
.factory('Machineprice', [ '$http',
function($http) {
return {
getPrices:function(){
return $http.get('/getPrices')
}
};
}
]
);
控制器
angular.module('core').controller('MachinePricingController', ['$scope','Machineprice',
function($scope, Machineprice) {
$scope.prices = Machineprice.getPrices();
console.log($scope.prices);
}
]);