0

I have a formarray in the form, Need to hide and show based on dropdown value - is_dependent_exist

I have tried like below:

var all_user_custom_fields = [
  {
    'field_name_slug': 'radio_button_with_group_custom_field8',
    'is_dependent_exist': 0
  },
  {
    'field_name_slug': 'radio_button_with_default_value',
    'is_dependent_exist': 1
  },
  {
    'field_name_slug': 'radio_button_with_mandatory',
    'is_dependent_exist': 1
  },
  {
    'field_name_slug': 'check_box_with_mandatory',
    'is_dependent_exist': 0
  }
];
<div  *ngFor="let CustomUser of custom_field_dataArray.controls; index as c;" [formGroupName]="c" class="col-12 md:col-6 lg:col-4  
*ngIf="all_user_custom_fields[c]?.is_dependent_exist != 1">
<input formControlName="{{all_user_custom_fields[c]?.field_name_slug}}" type="text" (keyup)="validate($event, c, all_user_custom_fields[c]?.field_name_slug)" pInputText />
</div>

Getting issue like Property 'c' does not exist on type 'UsersComponent'.

I need to display only is_dependent_exist = 0 value fields

1
  • Thank you Ghaith Arfaoui, But it's not working for me, Again getting Property 'c' does not exist on type Commented Jan 22, 2024 at 15:00

1 Answer 1

0

You can't use 2 directives (*ngFor and *ngIf) on the same element.

This should work :

<div *ngFor="let CustomUser of custom_field_dataArray.controls; index as c;" [formGroupName]="c" class="col-12 md:col-6 lg:col-4">
    <div *ngIf="all_user_custom_fields[c]?.is_dependent_exist != 1">
        <input formControlName="{{all_user_custom_fields[c]?.field_name_slug}}" type="text" (keyup)="validate($event, c, all_user_custom_fields[c]?.field_name_slug)" pInputText />
    </div>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

if you don't want create extra "tag" replace one of the divs by ng-content
a note to OP, if you do go down this route, you can stick an else in the if statement to display some other content like this stackoverflow.com/q/43006550/7147233

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.