1

我在java中有一个后端微服务,它使用注释(@NotBlank ...)处理表单验证。我已经使用 Angular 制作了前端。

验证逻辑工作正常。我遇到的问题是,当表单中出现错误(例如空字段)时,我的浏览器或 Angular 正在生成一个消息框,类似于您使用 alert() javascript 函数获得的消息框

(如果我被允许,我会发布一张图片)。

我不知道那个消息框来自哪里,我没有编码。目前我只是要求 angular 记录消息错误(它工作正常)

我的代码:

save() {
    this.service.addOne(this.protection).subscribe(
      () => {
        this.router.navigate(['/protections']).then();
        this.messageContainer = this.flashService.getMessageLang();
        this.flashService.defineFlash(this.messageContainer.ADDPROTECTION.SUCCESS, 1, "flash-message-green");
      },
      response => {
        if (response && response.error) {
          console.log('===========================================>');
          console.log(response.error.errors);
          ;
        }
      }
    );
  }

我想摆脱那个消息框。

我什至不确定这是 Angular 还是浏览器的问题。

我尝试在网上搜索答案,但空手而归。可能我的搜索措辞不正确,因为我不知道错误来自哪里。

知道如何摆脱消息框吗?

4

2 回答 2

1

Angular 有一个默认的错误处理程序,它记录错误和堆栈跟踪,以及显示错误屏幕(我假设这是您所描述的“消息框”。

您可以通过添加自己的自定义错误处理程序来更改默认行为。上面的文档链接中的说明和示例以及:

https://blog.angularindepth.com/expecting-the-unexpected-best-practices-for-error-handling-in-angular-21c3662ef9e4

于 2019-09-02T09:19:17.637 回答
0

您的代码中的这些行是什么?

this.messageContainer = this.flashService.getMessageLang();
this.flashService.defineFlash(this.messageContainer.ADDPROTECTION.SUCCESS, 1, "flash-message-green");

尝试评论他们?

于 2019-09-02T09:42:31.597 回答