1

I have an input and a button that reads the value and add it to the list.

Here is the code:

<div class="row mt-2">
    <div class="col-8">
        <input
           #sparePartsInput
           class="form-control"
           type="text"
           name="sparePart"
           maxlength="32"
           />
           {{sparePartsInput.value}}
    </div>
    <div class="col-4">
        <button
            [disabled]="sparePartsInput.value == '' || sparePartsInput.value.trim() == ''"
            type="button"
            class="btn btn-primary"
            (click)="addItemToSpareParts(sparePartsInput.value)>
            <i class="fa fa-plus"></i>
        </button>
    </div>
</div>

I set the button disabled when the value of the input is empty.

But when I select the value with CTRL+A and delete, its value seems not to empty. I need to click delete one more time and then it will be cleared. How can I fix this stuff?

1 Answer 1

1

Use [(ngModel)]="sparePartValue"

Try like this:

Working demo

<div class="row mt-2">
    <div class="col-8">
        <input
           #sparePartsInput
           class="form-control"
           type="text"
           name="sparePart"
           maxlength="32"
           [(ngModel)]="sparePartValue"
           />
           {{sparePartsInput.value}}
    </div>
    <div class="col-4">
        <button
            [disabled]=" sparePartValue == null ||sparePartValue == ''"
            type="button"
            class="btn btn-primary"
            (click)="addItemToSpareParts(sparePartsInput.value)">
            <i class="fa fa-plus"></i>Button
        </button>
    </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

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.