【发布时间】:2016-04-21 11:05:18
【问题描述】:
我开发了一个过滤器复选框,将参数传递给“仅使用照片过滤结果”。
如果我把下面的代码直接放在服务器上可以工作,但是通过 angular 会出错。
还有其他方法可以做到这一点吗?
$scope.query = {
picture: { $exists: true }
};
我的服务器路由器:
app.get('/api/users', ensureAuthenticated, function(req, res) {
console.log(req.query);
User.find(req.query, function(err, users) {
if (err) {
res.send(err);
}
res.json(users);
})
.sort({ rating: -1 });
});
还有我的控制器复选框:
<md-checkbox class="md-primary" ng-model="query.picture" ng-change="loadusers()">filter results only with photo</md-checkbox>
我的函数检索服务器
$scope.loadusers = function(){
$ionicLoading.show({
template: 'Carregando...'
});
diaristajaAPI.all('users').getList($scope.query)
.then(function(users){
$ionicLoading.hide();
$scope.listusers = users;
})
.catch(function(error) {
$ionicLoading.hide();
if (error.error) {
// Popup error - invalid redirect_uri, pressed cancel button, etc.
$mdToast.showSimple(error.error);
} else if (error.data) {
// HTTP response error from server
$mdToast.showSimple(error.data.message, error.status);
} else {
$mdToast.showSimple(error);
}
});
};
【问题讨论】:
-
我们需要显示您如何从 Angular 与服务器通信的代码
-
好的,走了!我的功能
标签: angularjs node.js express mongoose