Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在2中提交表单后导航另一页_Angular_Typescript - Fatal编程技术网

Angular 在2中提交表单后导航另一页

Angular 在2中提交表单后导航另一页,angular,typescript,Angular,Typescript,我有一个HTML表单,它捕获用户的输入并将其发送到数据库。我想做的是导航到另一个页面,如“详细信息”页面,您可以在其中自动看到所有输入的信息 我的方法是将值提交到数据库,并通过传递提交的id浏览详细信息页面。以下是我的TypeScript代码: submit() { this.participantService.add(this.participant).subscribe(participant => { this.alertifyService.success('partic

我有一个HTML表单,它捕获用户的输入并将其发送到数据库。我想做的是导航到另一个页面,如“详细信息”页面,您可以在其中自动看到所有输入的信息

我的方法是将值提交到数据库,并通过传递提交的id浏览详细信息页面。以下是我的TypeScript代码:

submit() {
  this.participantService.add(this.participant).subscribe(participant => {
  this.alertifyService.success('participant successfully added');
}, error => {
  this.alertifyService.error('Problem occured!\n' + error);
});

this.router.navigate(['participants/participants-details', this.participant.id]);
}

但是,这段代码只是将值发送到数据库。它不会带我进入
详细信息
页面。实现这一点的方法是什么?

在发送到详细信息页面之前,您不会等待数据提交完成。移动
router.navigate()
订阅的
成功
回调中

submit() {
  this.participantService.add(this.participant).subscribe(participant => {
      this.alertifyService.success('participant successfully added');
      this.router.navigate(['participants/participants-details', this.participant.id]);
  }, 
  error => {
    this.alertifyService.error('Problem occured!\n' + error);
   });
}
将“this.router.navigate”放入订阅功能。只有成功添加了参与者,而不是在此之前,您才能导航