Guest User

Untitled

a guest
Jan 24th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <form method="post" ng-submit="find()" name="findForm">
  2.  
  3. <div class="form-group">
  4. <input class="form-control input-lg" type="text" name="word"
  5. ng-model="word" placeholder="search from Mongo" >
  6. </div>
  7.  
  8. <button type="submit" class="btn btn-lg btn-block btn-success">search
  9. </button>
  10.  
  11. angular.module('MyApp')
  12. .controller('SearchCtrl', ['$scope', '$http', function($scope, $http) {
  13. $http.post('/api/search', $scope.word)
  14. $scope.search= function() {
  15. ({
  16. -----??
  17. });
  18. };
  19. }]);
  20.  
  21. app.post('/api/search', function(req, res) {
  22. Word.find(........)
  23. // here I dont know how ..
  24.  
  25. });
  26.  
  27. $scope.find = function() {
  28. $http.post('/api/search', $scope.word).then(function(response) {
  29. $scope.words = response.data;
  30. //your code
  31. });
  32. };
  33.  
  34. app.post('/api/search', function(req, res) {
  35. var query = {};
  36. //generetae query for partial search
  37. query.word = new RegExp(req.body.word, 'i');// assume word is field name for query.word
  38.  
  39. Word.find(query, function(error, words){
  40. if(error) {
  41. return res.status(400).send({msg:"error occurred"});
  42. }
  43. return res.status(200).send(words);
  44. });
  45. });
  46.  
  47. angular.module('SymText')
  48. .controller('FreeWrtCtrl', ['$scope', '$http', function ($scope, $http) {
  49.  
  50. $scope.find = function () {
  51. $http.post('/api/find',$scope.word)
  52. .then(function (response) {
  53. $scope.words = response.data;
  54.  
  55. })
  56. }
  57.  
  58. }]);
  59.  
  60. app.post('/api/find', function (req, res) {
  61.  
  62. var query={};
  63. query.word=new RegExp(req.body.word, 'i');
  64.  
  65. //console.log(req.body.word);
  66. User.find(query, function (err, words) {
  67. if (err) return res.status(400).send({msg:" error during search DB"});
  68. console.log(words);
  69. return res.status(200).send(words);
  70.  
  71. }
  72. )
  73.  
  74. var userSchema = new mongoose.Schema({
  75. username: {type: String, unique: true, required: true},
  76. password: {type: String, required: true},
  77. fullname: {type: String, required: true},
  78. role: Number
  79. });
Add Comment
Please, Sign In to add comment