A guide to adding specific data entries to MongoDB through AngularJS in the MEAN stack framework

When adding input values to mongodb using the scope name, all values are stored in an object and sent directly to the server for storage. I have 3 fields, but I want only the values from the 2nd textbox to be saved in the database while the rest should be NULL. How can I achieve this? Any help would be appreciated.

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>

Answer №1

app.js
  $scope.CreateNew = function () {

        $http.post('/CreateNewUser',{ 'Username': $scope.User.email}).then(function (res) {      

        });
    };

Answer №2

If you only need to send the email, follow these steps:

remove $scope.Contact.Name;

remove $scope.Contact.cellno;

Here is an example

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

        });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Which option is more beneficial for intercepting API data in Angular 6: interfaces or classes?

My API returns JSON data that is not structured the way I need it, so I have to make changes. { "@odata.context":"xxxxxx", "id":"xxxxxxxx", "businessPhones":[ ], "displayName":"name", "givenName":"pseudo", "jobTitle":null, "ma ...

Encountered an issue while trying to create a new controller in Angular, where the error indicated

Apologies for any language errors in advance. I recently delved into angular using the MEAN stack (MongoDB, Express, Angular, Node) and encountered an issue. Every time I try to create a simple Controller, I keep getting this error: Argument 'test ...

The most effective way to code overlapping html buttons

Can you help me figure out how to make clickable areas on my HTML5 web page without them overlapping? Here's what I'm trying to do: I want the red, blue, and green areas to be clickable links, but not overlap. For example, when clicking on the f ...

vue-router default route for children

Currently, I am working on a Vue 2.x application and utilizing vue-router for routing purposes. In certain situations, I need to directly display a child vue. The template structure is as follows: | voice 1 | voice 2 | voice 3 | | submenu 1 | submen ...

Setting a value for the identifier just one time

I've been grappling with an issue that's been on my mind for some time now. There are 14 divs on my webpage, and I need each one to be given a random ID (ranging from 1 to 14) every time the page loads. These divs all share the class ".image-box ...

Uncertain about the process of upgrading this chart with the latest array modifications

My code includes a function that updates the data array with user input, which is used to create a bar graph. The issue I am facing is that while the data array in the chart gets updated upon user input, the chart itself does not. How can I ensure that the ...

Automatically preselect the checkbox inputs with the API and update their status when they are interacted with

Hello fellow developer, I trust you are doing well. I am looking to have the checkboxes automatically checked based on data from the API and update their status when interacted with. I've tried different approaches but haven't found the right sol ...

The functionality of Material UI Slider components becomes less responsive when enclosed and rendered in JSX

Why is the Material UI's Slider not working smoothly when called in JSX as shown below? SliderAndValue.js import { Slider } from "@material-ui/core"; import { useState } from "react"; import "./styles.css"; export const ...

Create a delay effect in Vuex's action function

I am currently developing a Vue application for the backend and I want to introduce an artificial delay to actions. For example, when I submit a sign in request, I would like to add a 1-second delay before redirecting to the main application. This is the ...

Issues arise when the Angular controller fails to load

I'm experiencing an issue with my Angular controller where the code inside its constructor is not running. Here's a snippet of the relevant pieces: conversationcontrollers.js: var exampleApp = angular.module('exampleApp',[]); console ...

Combining URLs in Angular 6 - A Step-by-Step Guide

How can I concatenate the commonUrl from CommonClass in Angular 6 for category.service.ts? common-class.ts export class CommonClass { constructor(public commonUrl : string = 'http://localhost:3000'){}; } category.service.ts import { CommonC ...

Click to save image using jQuery

I am trying to implement a feature where clicking on an image allows users to download it. I am using the download attribute for this purpose. <a href="http://mysite.ru/userfiles/certificate_2.png" class="download-certificate-link" data-title="certific ...

Storing HTML form input data in the storage of an Android device

Is there a way to save HTML form input data using JavaScript in the local storage of an Android app? ...

Unable to accept the link ID in the modal

Presently, I am facing an issue with a modal that links a product with a customer and involves product discount calculations. The customer is automatically selected using the modal id, and the product is chosen through select options with a while loop. T ...

How can I generate a horizontal navigation bar using a JSON structure?

I have a JSON object that looks like this: var data = [ { "parent": "Home", "child": [ ] }, {"parent": "Services", "child": [ {"title":"Infrastructure"}, {"ti ...

What is the correct method to conceal the error message using JavaScript with document.getElementById("failedUpdateMessage").style.visibility = "hidden"

Once I had applied the code to conceal the element identified by the id "failedUpdateMessage", I now want to reveal that hidden element on a certain webpage using html. How can I achieve this using java script? I attempted to change "hidden" to "show" bu ...

Is there a way to incorporate jQuery into SharePoint 2010?

I am encountering an issue with linking my HTML page to our organization's SharePoint 2010 portal. All necessary files (CSS, images, jQuery) are stored in the same document library. While the CSS is functioning properly, I am facing challenges with ge ...

Troubleshooting Guide: Resolving the "No parameterless constructor defined for this object" error in your AngularJS/MVC application

I have a complex CRM page where users can schedule classes that they attend and learn from. The process involves filling out fields in a Modal and clicking Save, which then gathers the data and passes it to C#. However, in this particular instance, I&apos ...

How to Use Google Tag Manager to Track Forms with Various Choices

Currently, I am facing a challenge in setting up conversion tracking using GTM for a form that offers users multiple options via a drop-down menu. When the user clicks on an option, they are presented with choices like A, B, C, and D. After selecting an ...

Issues with Navigating through a Scrollable Menu

I'm having a difficult time grasping the concept and implementing a functional scrolling mechanism. Objective: Develop a large image viewer/gallery where users can navigate through images by clicking arrow keys or thumbnails in a menu. The gallery an ...