0

I am trying to load input as child component, and from the parent when we click on on-click function i want to toggle disable the input.

If i keep as basic input on the parent component its work as expected, but when i try to achieve the same as if the input loaded as child component, the disable is not happening.

please refer below stackblitx: https://stackblitz.com/edit/angular-input-disable-phjutj?file=app%2Fapp.component.html

1 Answer 1

1

Few issues with the code:

a) You are incorrectly using a field level attribute on an angular component. I changed it to

<app-number-field 
    formControlName="officeNumber" 
    [isDisabled]='disableTextbox'>
  </app-number-field>

b) you are not using the passed in input value so I added @Input() isDisabled: boolean; to the input component

c) Use that value that is being input from the parent component as such

<input class="number" type="number" pattern="[0-9]*" placeholder="{{placeholder}}" [value]="number" [disabled]="isDisabled" (change)="onNumberChange($event)" (keyup)="onNumberChange($event)">

d)There is a problem with your object.keys that is throwing an error - you have to fix it. Commenting out the select field gets the toggle working now

StackBlitz: https://stackblitz.com/edit/angular-input-disable-4dyjsw

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

4 Comments

thanks, its work as expected. one more question on top on this. suppose if we have more than one field with edit option. when we click on edit how to toggle the respective field to disable ? stackblitz.com/edit/angular-input-disable-7dq7gr?file=app/…
@Krish For this to work, you need to have the Edit button in the input component. So, toggle will affect only the input in that component. That would mean that you remove passing the boolean into the child-component.
what you mean that i have the edit button in the input component ? as part of that input component as a attribute [isDisabled] am i need to add one more for Edit ? or anything else you were trying to say ?
@Krish Is it necessary that you have the Edit button on the parent component? Why not just move the Edit button inside the input component in input.component.html ?

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.