0

Here's my code:

<tbody *ngFor="let user of users">
    <td>{{user.name}}:</td>
    <td>
        <ng-select  [items]="userList" bindValue="id" formControlName='id' bindLabel="label">
            <ng-template ng-option-tmp let-item="item">
                <div [ngbTooltip]="item.label" placement="bottom">{{item.label}}</div>
            </ng-template>
        </ng-select>
    </td>
</tbody>

userList: [
    { id: 1, label: 1 },
    { id: 2, label: 2 }
]

users: [
    { id: 5545, name: 'Z', value: 1 }
    { id: 1112, name: 'A', value: 2 },
    { id: 4455, name: 'B', value: 1 }
]

If userList.id == user.value then it's label should be selected in drop down.

Current Result:

enter image description here

Expected Result:

enter image description here

1 Answer 1

0

Found the solution.

formControlName='{{user.value}}' Instead of formControlName='id' works for me.

<tbody *ngFor="let user of users">
    <td>{{user.name}}:</td>
    <td>
        <ng-select  [items]="userList" bindValue="id" formControlName='{{user.value}}' bindLabel="label">
            <ng-template ng-option-tmp let-item="item">
                <div [ngbTooltip]="item.label" placement="bottom">{{item.label}}</div>
            </ng-template>
        </ng-select>
    </td>
</tbody>
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.