从angular2服务发送正文中的值

时间:2017-04-10 11:40:30

标签: node.js angular express angular2-services

我有一个Angular2服务

.switchMap(this::getStarredRepos)

发送请求
logIn (username, password): Observable<User[]> {
  return this.http.get(this.getUserUrl + username + '/' + password)
     .map(this.extractData)
     .catch(this.handleError);
}

但是我需要一种方式来发送router.get('/authenticate/:username/:password', function(req, res, next) { schema.User.find({ username: req.param("username"), password: req.param("password")}).exec(function (err, users) { if (err) return console.error(err); console.log("Load success: ", users); res.send(users); }); }); ,尤其是username以一种不会将其公开给请求本身的方式

1 个答案:

答案 0 :(得分:1)

您可以将方法更改为发布

logIn (username, password): Observable<User[]> {
  return this.http.post(this.getUserUrl + "test", {username: username, password: password})
     .map(this.extractData)
     .catch(this.handleError);
}

节点:

router.post('/authenticate/test', function(req, res, next) {
 var username = req.body.username;
 var password = req.body.password;
 schema.User.find({ username: username, password: password }).exec(function (err, users) {
    if (err)
      return console.error(err);
      console.log("Load success: ", users);
      res.send(users);
   });
});