【问题标题】:angular reactive form does not hit api when form validation is applied应用表单验证时,角度反应形式不会命中 api
【发布时间】:2020-11-25 12:38:16
【问题描述】:

我有一个必须在检查表单验证后提交的表单。但是当我提交表单时,它不会向 API 发出请求。

我的 component.html 文件

       <form
          class="forms"
          [formGroup]="addContainerForm"
          (ngSubmit)="addAnalyticsSubmit(addContainerForm.value)"
        >
       // some code
       </form>

我的 component.ts 文件

       addContainerForm(v){
            this.new = v
           const a = {
      Name: this.new.nameValue,
       Coordinates: this.coordinates,
         };
       if (this.addContainerForm.valid) {
        this.service.postContainer(a).subscribe(
      (res: any) => {
      console.log(res)})
        }

           }

不知道为什么应用检查条件进行表单验证时API没有命中。请告诉我我做错了什么。

【问题讨论】:

  • 您应该尝试调试您的表单组以获取验证错误以及什么不起作用!

标签: angular


【解决方案1】:

由于您没有分享足够的信息来理解您的问题。 Angular 官方文档已经很好地解释了表单的基础知识https://angular.io/guide/http

这里也解释了验证。 https://angular.io/guide/form-validation

【讨论】:

    【解决方案2】:

    我在表单构建器组中添加了不必要的字段,我没有在我的表单中使用,因为它总是从表单验证中返回 false。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-27
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 2022-11-25
      • 2020-01-17
      • 2018-09-18
      • 1970-01-01
      相关资源
      最近更新 更多