1

I've searched the web. I found a couple of things but I wasn't able to understand anything out.

I'm trying to send a get request from my angular to Node.js server. I want to send some search parameters for the my server. and it searches then returns the documents.

I'm tring this function to get send the request. But I don't know how to ad parameters beside this request.

GetCases(){
        return this.http.get('/api/saleCases')
        .map((response:Response)=>response.json());
    }

In the server side

router.get('/saleCases', function(req, res){
    console.log('get request for all cases');
    Case.find({}).exec(function(err, cases){
        if(err){
            console.log("error retriving videos");
        }else{
            res.json(cases);
        }
    });
});

Can you help me to add the parameters in angular and read them in node.js? Or is there any kind of way that you can suggest me to use?

1

1 Answer 1

2

In Client side, first init your search parameters, something like:

const searchParams = {
    params: {
        param1: val1,
        param2: val2,
        ...
    }
}

then send your request to Server side like:

return this.http.get('/api/saleCases', searchParams)

In Server side you can access the params, using:

router.get('/saleCases', function(req, res){
    const param1 = req.query.param1;
    const param2 = req.query.param2;
});
Sign up to request clarification or add additional context in comments.

2 Comments

It errors on searchParams. it says: [ts] Type '{ param1: number; param2: number; }' has no properties in common with type 'RequestOptionsArgs'.
I believe it expects a params property (angular.io/api/http/RequestOptionsArgs). please try: const searchParams = { params: { param1: val1, param2: val2, } },

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.