Angular 2 - Checking for server errors from subscribe

前端 未结 2 1445
南笙
南笙 2020-12-08 00:18

I feel like this scenario should be in the Angular 2 docs, but I can\'t find it anywhere.

Here\'s the scenario

  1. submit a form (create object) that is i
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 00:35

    You can achieve with following way

        this.projectService.create(project)
        .subscribe(
            result => {
             console.log(result);
            },
            error => {
                console.log(error);
                this.errors = error
            }
        ); 
    }
    
    if (!this.errors) {
        //route to new page
    }
    

提交回复
热议问题