1

I am doing inline editing. I want input to be disabled until user clicks edit button, opposite for save button. I am trying to set it [disabled]="!hidemeSub[index]" like this but it doesn't work. What am I doing wrong?

.html

  <div *ngFor="let item of items; let index = index">
    <form [formGroup]="rates">
      <div  formGroupName="type">
        <div [hidden]="hidemeSub[index]"
          (click)="hidemeSub[index] = !hidemeSub[index];">Edit</div>
        <div (click)="editRates(item.id, index)" [hidden]="!hidemeSub[index]">Done</div>
        <div formArrayName="options">
          <ng-container [formGroupName]="index">
              <input type="text" class="form-control" [disabled]="!hidemeSub[index]" formControlName="rateRangeFrom">
              <input type="text" class="form-control" [disabled]="!hidemeSub[index]" formControlName="rateRangeTo">
          </ng-container>
        </div>
      </div>
    </form>
  </div>

.ts

hidemeSub = {};
1
  • Are you getting errors? Also, hidemeSub is an object, you cannot iterate it with index. So, please provide more code from ts. Commented Feb 21, 2022 at 6:02

1 Answer 1

2

You need to use [attr.disabled] instead of [disabled]

<input type="text" class="form-control" [attr.disabled]="!hidemeSub[index]" formControlName="rateRangeFrom">

And value passed should either hold true or null

Simple working example https://stackblitz.com/edit/angular-ivy-87nxyh?file=src/app/app.component.html

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

2 Comments

hi! thanks for the answer! yes, but now input is always disabled, it doesnt toggle
@aelin_galathius I have added a working example to the answer. Can refer to it

Your Answer

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