1

So I need to create this function:

  buildForm(): void {

    console.log('build form');
    this.notificationForm = this.fb.group({
      appCreated: [],
      appSubmittedReview: [],
      appCancelReview: [],
      appRequestForDeletion: [],
      appDisable: [],
      appReEnable: [],
      appReviewPublished: [],
      appReviewApproved: [],
      appReviewDeleted: [],

    });
  }

All the fields are a checkbox and I want that by default those to be not checked, can anyone help me with creating this buildForm. Thanks in advance

2 Answers 2

1

The field's status depend on the default value of FormBuilder, try this:

  this.notificationForm = this.fb.group({
      appCreated: [true],
      appSubmittedReview: [],
      appCancelReview: [],
      appRequestForDeletion: [],
      appDisable: [true],
      appReEnable: [],
      appReviewPublished: [],
    });

in HTML

   <form [formGroup]="notificationForm" (ngSubmit)="onSubmit()">
         appCreated:  <input type="checkbox" formControlName="appCreated" >
         appSubmittedReview:  <input type="checkbox" formControlName="appSubmittedReview" >
         appCancelReview:  <input type="checkbox" formControlName="appCancelReview" >
         appRequestForDeletion:  <input type="checkbox" formControlName="appRequestForDeletion" >
         appDisable:  <input type="checkbox" formControlName="appDisable" >
         appReEnable:  <input type="checkbox" formControlName="appReEnable" > 
      </form>

Working Demo

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

2 Comments

I want them to be false if nothing comes from the backend if I selected sth I get what I have set in build form and not the real values, can you help with that
try to add a submit button to check what i mean in html
1

use false as a default value

buildForm(): void {

    console.log('build form');
    this.notificationForm = this.fb.group({
      appCreated: false,
      appSubmittedReview: false,
      appCancelReview: false,
      appRequestForDeletion: false,
      appDisable: false,
      appReEnable: false,
      appReviewPublished: false,
      appReviewApproved: false,
      appReviewDeleted: false,

    });
}

1 Comment

will this not influenced if in API for example i get some of them true ??

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.