0

I have this form and the data is not appear they do not pass to my back end :

<div ng-controller="searchController">
<form ng-submit="submit()">
    <input type="text" name="name" ng-model="namegirl" />
    <input type="text" name="namewod" ng-model="namewod" />
    <input type="submit"/>
</form>

Now in my controller in script.js is this:

myApp.controller('searchController', ['$scope', '$filter', '$http', function ($scope, $filter, $http) {

    let data = {
        namegirl  :$scope.namegirl,
        name      :$scope.namewod
    };

    console.log(data);

    $http.post('/wodsearch',data)
    .success(function (response) {
        console.log(response.data);
    })
    .error(function (response, status) {
        console.log(response);
    });

}]);

Now i wand to pass my data from my form to the nodejs in my server i have this code:

app.post('/wodsearch',function(req, res ,next){
    // how to get here the data from my angular  
}); 
erevos13
  • 141
  • 2
  • 11
  • Possible duplicate of [How do I consume the JSON POST data in an Express application](https://stackoverflow.com/questions/10005939/how-do-i-consume-the-json-post-data-in-an-express-application) – Punit Gupta Sep 01 '17 at 13:01

2 Answers2

1

You call ng-submit="submit()" when you post the form but there is no submit() method in the searchControllers scope. Add it like this

myApp.controller('searchController', ['$scope', '$filter', '$http'
, function ($scope, $filter, $http) {

    $scope.submit = function (){
        let data = {
            namegirl  :$scope.namegirl,
            name      :$scope.namewod
        };

        console.log(data);

        $http.post('/wodsearch',data)
        .success(function (response) {
            console.log(response.data);
        })
        .error(function (response, status) {
            console.log(response);
        });
    };
}]);
Marcus Höglund
  • 13,944
  • 9
  • 42
  • 63
0

Assuming you're using Express. Then the data should be in req.body.

GMaiolo
  • 3,255
  • 1
  • 16
  • 33