1

I store input values into mongodb using scope name. I have a 3 fields when I click add all values are in object so I directly send the scope name into server and store it.

I would like to store only 2nd textbox values and remaining values should be NULL into the database. But I don't know how to do this. Anyone can help me?

Server.js

app.post('/AddNewcontact', function (req, res) {
    db.Manage_Facility.insert(req.body, function (err, docs) {
        console.log(docs);
        res.json(docs);
    });
});

controller.js

$scope.AddNew = function () {
        $http.post('/AddNewcontact', $scope.Contact).success(function (response) { 

        });
    };

html

<input type="text" name="Name" class="form-control" ng-model="Contact.Name">
<input type="text" name="email" class="form-control" ng-model="Contact.email">
<input type="text" name="cellno" class="form-control" ng-model="Contact.cellno">
<button class="btn btn-primary" ng-click="AddNew()" >Submit</button>
Loic P.
  • 691
  • 6
  • 18
jose
  • 1,044
  • 1
  • 12
  • 35

2 Answers2

1
controller.js
  $scope.AddNew = function () {

        $http.post('/AddNewcontact',{ 'Name': $scope.Contact.email}).success(function (response) {      

        });
    };
jose
  • 1,044
  • 1
  • 12
  • 35
0

Let's say you want to send just the email, do following :

delete $scope.Contact.Name;

delete $scope.Contact.cellno;

here is example

$http.post('/AddNewcontact', $scope.Contact).success(function (response) {      

        });
jose
  • 1,044
  • 1
  • 12
  • 35
inQstvJS
  • 303
  • 2
  • 6