【问题标题】:Send Email when user is subscribed用户订阅时发送电子邮件
【发布时间】:2019-12-08 02:39:53
【问题描述】:

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

我想在我的 angular Front-end 中调用它所以我在 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");
})

}

这样可以吗,不然怎么办

【问题讨论】:

  • 所以你想在 addUser 之前调用 validate?
  • 是的!确切地。所以我可以向订阅者发送验证电子邮件

标签: node.js angular mean nodemailer


【解决方案1】:

使用 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
      }
    }

【讨论】:

    猜你喜欢
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-12
    • 2010-11-01
    • 1970-01-01
    相关资源
    最近更新 更多