0

I've a form array named Questions inside which there are FormControls like QuestionText, AnswerType and AnswerList(this is also a form array). I've seperate buttons for adding questions as well as for adding answers to this Answerlist. Everything works fine except for the (add ans) button. I don't want this button to be visible all the time. If the user selects the AnswerType as single choice, the button should be displayed. If the user selects the AnswerType as Boolean, the button should not be displayed. enter image description here

<div formArrayName="Questions" >
<div 
  *ngFor="let filter of QuestionsFormArray.controls; let j = index;">
  <div [formGroupName]="j">
    <mat-form-field>
      <input matInput formControlName="displayText" placeholder="Question Text">
    </mat-form-field>
    <mat-form-field>
        <select formControlName="AnswerType" placeholder="Select AnswerType" (change)="changeanswertype($event,j)" matNativeControl required>
          <option *ngFor="let item of AnswerType" [value]="item.type">
            {{item.type}}</option>
        </select>
      </mat-form-field>
      <div>
        <button *ngIf="filter['controls'].AnswerType!='Boolean'" class="btn btn-select rightfloat" (click)="AddAnswer(filter.controls.Answers, j)">Add ans</button>
      </div> &nbsp;&nbsp;&nbsp;
      <mat-icon class="deleteicon"
      (click)="removeFilterFromQuestionsFormArray(j)">
      delete
    </mat-icon>
  <div formArrayName="Answers" >
    <div *ngFor="let ans of filter['controls'].Answers['controls']; let k = index;">
        <div [formGroupName]="k" >
    <mat-form-field>
        <input 
          matInput 
          formControlName="text" 
          placeholder="AnswerText">
      </mat-form-field>
      <button type="button" class="close" aria-label="Close" (click)="removeanswer(j,k)">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
    </div>
  </div>
  </div>
</div>

5
  • Please add some code to help you properly.. :) Commented Jan 23, 2020 at 10:46
  • 2
    have you looked at *ngIf? Commented Jan 23, 2020 at 10:46
  • @GuruprasadRao I've added what I had tried Commented Jan 23, 2020 at 11:55
  • @PierreDuc I've already tried using *ngIf but it makes no change to the UI. Commented Jan 23, 2020 at 11:56
  • Could you please add your project in stackblitz Commented Jan 23, 2020 at 12:21

0

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.