无法在get方法中将复杂对象从Angular传递给Nodejs

时间:2018-04-18 07:10:18

标签: node.js angular angular2-routing angular5

我试图在以下代码中将对象从angular传递给节点js:

Angular:

let data = {module: "master",identifier: "personneltype"};

return this._http.get("http://localhost:3000/api/Personnel/GetGlobalConfig",{params:data})  
.map((response:Response)=><IGlobalConfig[]>response.json())
 .catch(this.handleError);

节点

function getGlobalConfig(req, res, next) {
    pool.connect(function (err, client, done) {
        var q ='select * from abc.table($1:: character varying(150), $2:: character varying(150))';
        client.query(q,[req.params.module,req.params.identifier], function (err, result) {
            done();
            if (err) {
                console.log(err);
                res.status(400).send(err);
            }
            res.status(200).send(result.rows);
        });
    });
};

路线:

router.get('/getGlobalConfig/:module&:identifier',db.getGlobalConfig);//not sure what this should be

此角度代码有效:

let data = {module: "master",identifier: "personneltype"};

    return this._http.get("http://localhost:3000/api/Personnel/GetGlobalConfig/"+data.module+"&"+data.identifier)  
    .map((response:Response)=><IGlobalConfig[]>response.json())
     .catch(this.handleError);

1 个答案:

答案 0 :(得分:0)

let data = new HttpParams();
data = data.append('module', 'master');
data = data.append('identifier', 'personneltype');

return this._http.get("http://localhost:3000/api/Personnel/GetGlobalConfig",{params:data})  
.map((response:Response)=><IGlobalConfig[]>response.json())
 .catch(this.handleError);