How to access Angular Js data from nodejs

srsxyz

Hi in my angular js file, I have patient objects which contain name, number and appointment date. In my node js file, I use twilio to send a text a patient. What I want to know is how to get the number from the angular js file in order to use it in my node Js file so I can send the patient a text. Thanks.

here is the part of server.js where I send the text message

app.post('/testtwilio', function(req,res){

    var cheerio = require('cheerio'),
     $ = cheerio.load('file.html'),
     fs = require('fs');
 fs.readFile('./views/index.html', function (err, html) {
    if (err) {
        throw err; 
    } else {
        $ = cheerio.load(html.toString());
        console.log($scope.patients)//$('.reminder').attr('text'));   
    }
    });
    client.sendMessage({
        to: '{{patient.number}}',
        from: '+16173935460',
        body: 'Text sent using NodeJS'
    }, function(err, data){
        if(err)
            console.log(err);

    });
})

Here is the patient object in the MainController.js

$scope.patients = [
      {
        name: 'John Smith',
        date: "12/22/2016",
        number: 1829191844
      },
      {
        name: 'Matt',
        date: "09/15/2016",
        number: 1829198344
      },
      {
         name: 'John',
        date: "08/25/2016",
        number: 1829198844
      },


   ];
joncodo

Pass the data from the front end to the backend? Have angular call a route on your backend with the data you need and access it with the req.params object.

Is your server.js a node.js controller?

In the angular controller you could import $http and just do a $http.post({myparams}, /myRoute, function(results){console.log(results)})

Like Mike says. The only way to really share files between the front end and the backend is if the files are JSON as that can be read by Angular and Node. However, I usually just use this for static configuration files.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to pass form data from angular to nodejs

How to fetch data from nodejs in Angular

Angular Nodejs : Output is Undefined, Can't access the data from the server

how to access data from json response angular

How to access index.js from static page in NodeJS

Angular JS access $http data from factory in controller

How to post multipart/form-data from Angular to Nodejs Multer?

$http in Angular how to post from form data in to nodejs

Access Json data in angular js

How to access parent controller data inside child controller in angular js

How to access Angular JS custom filter JSON data in view

Angular Access data from Service

Angular: How to access ActivatedRoute snapshot data from another component

How to access data from observables in angular using httpClient?

How to pass and access data from a dialog component in angular?

How to access Array value from outside scope with Angular JS

How to access specific data values from tooltip - Chart.js

How to access data from outside the instance in Vue js?

How to access data from computed property Vue.js

How to access json file data from js file

Nodejs how to access SerialPort path on 'data' event

How to access session data without request in NodeJs?

How to access js file in Angular

Not getting data from a NodeJs API in Angular?

How to access NodeJS from another network

How to pass json data from C# controller to angular js?

how to pass data from service to directive in angular.js

How to pass data from factory to controller in angular js?

How to get data from spring controller to angular js