用户订阅时发送电子邮件

Send Email when user is subscribed

我在后端写了这个方法 router.put('/validateAccount', function (req, res) {//这里是实现nodemailer的代码}

我想在我的 angular 前端调用它所以我在 inscription.service.ts

中写了一个函数
ValidateAccount(user){
// var headers = new Headers({ 'Content-Type': 'application/json' });
// let options = new RequestOptions({ headers: headers });
return this.http.post('http://localhost:3333/api/validateAccount',user)   .map((response: Response) => response.json(),err =>err)

}

并且我想在 inscription.component.ts 中的同一函数中使用它,该函数从同一服务调用 AddUser() 方法

register(event) {
event.preventDefault();
let newUser = {
  type:"particulier",
  login:this.login,
  email: this.email,
  tele: this.tele,
  pass: this.pass,
  confpass: this.confpass
}
this.inscriptionService.AddUser(newUser).subscribe(res => {
  console.log(res)
  this.formSubmitAttempt = true;
  this._router.navigate(['/inscription']);

},err=>{
  // console.log(err)
  // this.message = "email existe déjà"
  // this.showMessage = true;
  alert("email existe deja");
})

}

可以吗,不然怎么办

使用 RxJS 有更好的方法(比如使用 flatMap 而不是订阅第一个 http 调用)但应该这样做:

this.inscriptionService.AddUser(newUser).subscribe(res => {
      console.log(res)
      this.formSubmitAttempt = true;
      this._router.navigate(['/inscription']);
      this.inscriptionService.ValidateAccount(res).map(res => {
        // do something
      }
    }