0

I'm facing a problem, mainly I cannot fill a value in input but in the HTML. I searched but nothing seems to work. I tried value, (value), [(value)], "k.bag.ConstructionYear", "{{k.bag.ConstructionYear}}" and other combinations and nothing seems to work.

mycomponent.html

<ng-container
  *ngIf="{
    // other stuff
    firstStepState: firstStepState$ | async
  } as o"
>
  //........
  <ng-container *ngIf="{
          bag : testService.getData(o.firstStepState.value1, o.firstStepState.value2) | async
        } as k">

    <ng-container *ngIf="k.bag !== undefined && k.bag !== null">
    {{k.bag.ConstructionYear}} // <-- this is showing 

    <input
        type="text"
        name="constructionYear"
        formControlName="constructionYear"
        id="constructionYear"
        data-test="constructionYear"
        placeholder=""
        [value]="k.bag.ConstructionYear" <-- this is the problem
    />
    

2 Answers 2

1

by assigning formControlName="constructionYear" to the input, you delegate value control of this input to your formControl. from this point of time you should update the logical form from your ts code whenever you want, not the value of the input. for example through method control.setValue(newValue)

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

Comments

0
<input
    type="text"
    name="constructionYear"
    formControlName="constructionYear"
    id="constructionYear"
    data-test="constructionYear"
    placeholder=""
    [(ngModel)]="k.bag.ConstructionYear"
/>

for binding with your data

1 Comment

Don't mix reactive form models with template form models. i.e. the formControlName and the ngModel attribute should not both be on the same element.

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.