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>

2 Answers 2

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

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

        });
    };
Sign up to request clarification or add additional context in comments.

Comments

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) {      

        });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.