我正在尝试注册用户,同时在点击注册按钮时发送电子邮件。
组件
register() {
this.userService.register(this.registerForm.value).subscribe(
res => {
console.log(this.token);
this.toast.setMessage('you successfully registered!', 'success');
this.router.navigate(['/login']);
},
error => this.toast.setMessage('email already exists', 'danger')
);
}
服务
register(user): Observable<any> {
return this.http.post('/api/user', JSON.stringify(user), this.options);
}
节点邮件程序API
var headers = new Headers();
var creds = 'emailid=' + user.email ;
var emailid = 'emailid=' + user.email;
headers.append('Content-Type', 'application/X-www-form-urlencoded');
this.http.post('http://localhost:3000/sendmail', emailid, {headers: headers}).subscribe((data) => {
if(data.json().success) {
console.log('Sent successfully');
}
})
我希望邮件API采用register方法。任何人都可以帮助我吗?
答案 0 :(得分:1)
为什么不在注册成功回调下放置用于发送邮件的代码:
组件:
this.userService.register(this.registerForm.value).subscribe(
res => {
this.http.post('http://localhost:3000/sendmail', emailid, {headers: headers}).subscribe((data) => {
if(data.json().success) {
console.log('Sent successfully');
}
})
this.router.navigate(['/login']);
},
error => this.toast.setMessage('email already exists', 'danger')
);
答案 1 :(得分:0)
我得到了答案。
test = df2[df1, on=.(bike_id, time = time), roll="nearest",
.(bike_id, time, st_x, st_y)]
服务
register() {
this.userService.register(this.registerForm.value).subscribe(
res => {
console.log(this.token);
this.toast.setMessage('you successfully registered!', 'success');
this.router.navigate(['/login']);
},
error => this.toast.setMessage('email already exists', 'danger')
);
this.userService.email(this.registerForm.value);
}