Home > Software design >  ng-autocomplete displaying '[object Object]'
ng-autocomplete displaying '[object Object]'

Time:10-22

TS Code:

public TitleSelected: BaseEntity;

...

this.TitleSelected= {id: this.model.titleId, title: this.model.title};

HTML Code:

<ng-autocomplete [(ngModel)]="TitleSelected" [data]="titles" [searchKeyword]="keyword" 
       (inputChanged)='onChangeSearchTitle($event)' notFoundText="موردی یافت نشد" 
       [notFoundTemplate]="notFoundTemplate" [isLoading]="loadingTitleList" [minQueryLength]="0" 
       [itemTemplate]="itemTemplate" heading="لیست عنوان های موجود در سیستم" 
       historyIdentifier="Title_Titles_History" [historyHeading]="historyHeading" 
       historyListMaxNumber="10" placeHolder="عنوان محصول"> 
</ng-autocomplete>

[initialValue] is not work

CodePudding user response:

Don't know why you getting this [object object] error but i made one stackblitz example for you.

You can check it out for your reference and work accordingly because it work at my end.

Here is the link of stackblitz : Stackblitz Demo

CodePudding user response:

Please check the model values and their datatype if it is same as in list you provided to autocomplete, i am sure this will be the issue.

this.TitleSelected= {id: this.model.titleId, title: this.model.title};

For testing purpose you can set staic values:

this.TitleSelected= {id: 2, title: 'Test'};
  • Related