我正在尝试为我的平均堆栈Web应用创建搜索,这是我到目前为止所做的:搜索栏的导航栏格式为btw
exports.search = function(req, res) {
Produit
.find({
$text: {
$search: req.params.term
}
})
.populate('categories')
.exec()
.then(respondWithResult(res))
.catch(handleError(res));
};
router.get('/:term/search', controller.search);
this.search = function() {
$rootScope.$broadcast('search:term', this.searchTerm);
console.log('it works !!');
};
<input id="searchBox" type="text" class="form-control input-large" placeholder="Search" ng-model="searchTerm" ng-change="navCtrl.search()">
function produitsService($resource, $timeout, Upload, $q) {
var resource = $resource('/api/produits/:id/:controller', null, {
update: {
method: 'PUT'
},
catalog: {
method: 'GET',
isArray: true,
params: {
controller: 'catalog'
}
},
search: {
method: 'GET',
isArray: true,
params: {
controller: 'search'
}
},
constructor(Produit, $rootScope) {
this.produits = Produit;
$rootScope.$on('search:term', function(event, data) {
this.produits = Produit.search({id: data});
});
}
GET http://localhost:3000/api/produits/search 500 (Internal Server Error)
angular.js:14961 Possibly unhandled rejection: {"data":{"message":"Cast to ObjectId failed for value \"search\" at path \"_id\" for model \"Produit\"","name":"CastError","stringValue":"\"search\"","kind":"ObjectId","value":"search","path":"_id"},"status":500,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"/api/produits/search","headers":{"Accept":"application/json, text/plain, */*","X-XSRF-TOKEN":"k8ucUq1x0kickvmqcxfuuGZHxHNXWDzEpWleg="}},"statusText":"Internal Server Error","xhrStatus":"complete","resource":[]}
GET /api/produits/search 500 20.806 ms - 190
GET /api/produits/search 500 8.705 ms - 190
GET /api/produits/search 500 18.085 ms - 190