1

vatCodeList is an error with string codes.

Example: ['34u' , '23' ,'tt']

Need to set the selected value there.

<select class="custom-select" formControlName="vatCode">             
  <option *ngFor="let i of vatCodeList">{{i}}</option>          
</select>
1

3 Answers 3

1

Inside your *.component.ts

public vatCode: any;

Inside your *.component.ts you can set the value of vatCode to one of the values contained within vatCodeList, this will update the selected value.

Inside the *.component.html

<select class="custom-select" formControlName="vatCode" [(ngModel)]="vatCode">             
  <option *ngFor="let i of vatCodeList">{{i}}</option>          
</select>
Sign up to request clarification or add additional context in comments.

Comments

0

You can bind the value property like this

<option [value]="i" *ngFor="let i of vatCodeList">{{ i }}</option>

Comments

0

You can try to put an expression to the option tag to make an option selected

<select class="custom-select" formControlName="vatCode">             
            <option *ngFor="let i of vatCodeList" {{i == vatCode?'selected':'' }}>{{i}}</option>          
</select>

The variable should reference the value of the InputControl. Using reactive forms it would be easy to extract the value and put it into expression.


The easiest way to bind the element to the model with ngModel but you can check if this solution helps.

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.