Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form method="post" ng-submit="find()" name="findForm">
- <div class="form-group">
- <input class="form-control input-lg" type="text" name="word"
- ng-model="word" placeholder="search from Mongo" >
- </div>
- <button type="submit" class="btn btn-lg btn-block btn-success">search
- </button>
- angular.module('MyApp')
- .controller('SearchCtrl', ['$scope', '$http', function($scope, $http) {
- $http.post('/api/search', $scope.word)
- $scope.search= function() {
- ({
- -----??
- });
- };
- }]);
- app.post('/api/search', function(req, res) {
- Word.find(........)
- // here I dont know how ..
- });
- $scope.find = function() {
- $http.post('/api/search', $scope.word).then(function(response) {
- $scope.words = response.data;
- //your code
- });
- };
- app.post('/api/search', function(req, res) {
- var query = {};
- //generetae query for partial search
- query.word = new RegExp(req.body.word, 'i');// assume word is field name for query.word
- Word.find(query, function(error, words){
- if(error) {
- return res.status(400).send({msg:"error occurred"});
- }
- return res.status(200).send(words);
- });
- });
- angular.module('SymText')
- .controller('FreeWrtCtrl', ['$scope', '$http', function ($scope, $http) {
- $scope.find = function () {
- $http.post('/api/find',$scope.word)
- .then(function (response) {
- $scope.words = response.data;
- })
- }
- }]);
- app.post('/api/find', function (req, res) {
- var query={};
- query.word=new RegExp(req.body.word, 'i');
- //console.log(req.body.word);
- User.find(query, function (err, words) {
- if (err) return res.status(400).send({msg:" error during search DB"});
- console.log(words);
- return res.status(200).send(words);
- }
- )
- var userSchema = new mongoose.Schema({
- username: {type: String, unique: true, required: true},
- password: {type: String, required: true},
- fullname: {type: String, required: true},
- role: Number
- });
Add Comment
Please, Sign In to add comment