0

I have a form which has to be submitted after checking form validations. But when I submit the form it does not to make a request to API.

my component.html file

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

my component.ts file

       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)})
        }

           }

I don't know why API is not hit when the check condition is applied for form validation. Please, tell me what I am doing wrong.

1
  • You should try to debug your formgroup to get th validation errros and what's not working with it! Commented Nov 26, 2020 at 8:36

2 Answers 2

1

Since you have not shared enough information to understand your problem. Angular official docs have very well explained the basics of forms https://angular.io/guide/http

Also the validation has been explained here. https://angular.io/guide/form-validation

Sign up to request clarification or add additional context in comments.

Comments

0

I have added unnecessary fields in the formbuilder group which i am not using in my form due to which it always return false from form validation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.