[英]How to set defualt value for primeng autocomplete <p-autocomplete>
I tried below but didn't worked.我在下面尝试过,但没有奏效。
Added below to <p-autocomplete>
在下面添加到<p-autocomplete>
[ngModelOptions]="{standalone: true}"
and [(ngModel)]="sampleModelData"
[ngModelOptions]="{standalone: true}"
和[(ngModel)]="sampleModelData"
and in .ts file added并在 .ts 文件中添加
this.sampleModelData='ramesh';
even I tried setting as below in .ts file but this too didn't work.即使我尝试在 .ts 文件中进行如下设置,但这也不起作用。 (<HTMLInputElement>document.getElementById('sampleModelData')).value='ramesh123';
How to resolve issue如何解决问题
you need to get a reference to the autocomplete component that you can access to the input native element您需要获取对可以访问输入本机元素的自动完成组件的引用
@ViewChild('autoItems', { static: true }) public autoItems: AutoComplete; // 👈
setAutoValue() {
this.selectedValue = {label:'Apple' , value:'apple'};
this.autoItems.inputEL.nativeElement.value = this.selectedValue.label; // 👈
}
template模板
<p-autoComplete [(ngModel)]="selectedValue" field="label" [suggestions]="result"
(completeMethod)="search($event)"#autoItems>
</p-autoComplete>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.