How to fix Type 'unknown' cannot be used as an index type

Viewed 1016

The above error occurs frequently. How to fix this. Below is the code

 <div class="col-4 col-md-3 col-lg-3" *ngFor="let in_settings of invoice_settings | keyvalue">
                                                <div cdkDropList class="example-list"
                                                    (cdkDropListDropped)="drop($event)">
                                            
                                                </div>
                                                <div class="settings_border">
                                                    <div class="row settings_title">
                                                        <div class="col-lg-8">
                                                            <h5 class="mt-0 task-header header-title">{{invoice_settings_title[in_settings.key]}}
                                                            </h5>
                                                        </div>
                                                        <div class="float-right mt-2 mr-a">
                                                            <a href="javascript:void(0);" (click)="add('invoice',invoice_settings_title[in_settings.key],invoice_settings_key[in_settings.key])" class="co-w add_settings">
                                                                <i-feather name="plus-circle"></i-feather>
                                                            </a>
                                                        </div>
                                                    </div>
</div>

invoice_settings is sent in the component.ts file.

1 Answers

from the code I understand you are not using the value of invoice_settings object and u need the keys alone. May be use Object.keys(invoice_settings) in ngFor and remove keyvalue pipe which will result in array and this error should no longer occur.

Related