我在后端写了这个方法 router.put('/ validateAccount',函数(req,res){//这是实现nodemailer的代码}
我想在有角度的前端中调用它,所以我在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");
})
}
那有可能吗,否则我该怎么做
答案 0 :(得分:0)
有更好的方法可以使用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
}
}