Monday, 10 April 2017

how to pass a value form angularjs to node [duplicate]

This question already has an answer here:

Hi everyone i have a problem with passing value from angular to node... I want get limit value on server and pass it to limit

this is my Server:

app.get("/movies", function(req, res) {

var limit = req.query.limit; // i can't get this (variable is undefined)
console.log(limit);

MongoClient.connect(dbUrl, function(err, db) {
    if (err) {
        res.status(500);
        res.json({ error: true });

        return;
    }

    db.collection("movies").find({}, { limit: limit }).toArray(function(err, docs) {

        if (err) {
            res.status(500);
            res.json({ error: true });

            return;
        }

        res.json(docs);

        db.close();
    });

});

});

Controller

Ctrls.controller('movies', ['$scope', "$http", "$location", function($scope, $http, $location) {


    $scope.data = [];
    var request = $http.get('/movies', {
        limit: 2
    });
    request.success(function(data) {
        $scope.movies = data;
        console.log(data);

    });
    request.error(function(data) {
        console.log('Error: ' + data);
    });


}]);

I want get the value 'limit' in node, what i do wrong ? In server variable is undefined (x2)

thanks



via Marcin Jendruchniewicz

No comments:

Post a Comment