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  
}); 
1

2 Answers 2

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);
        });
    };
}]);
Sign up to request clarification or add additional context in comments.

Comments

0

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

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.