简体   繁体   English

如何从 PrimeNG 自动完成聚焦到输入框?

[英]How to focus into an input box from PrimeNG autocomplete?

I want to focus into inputbox after PrimeNg autocomplete onSelect event click.我想集中到inputboxPrimeNg autocomplete onSelect事件点击。

<p-autoComplete [(ngModel)]="itemIdAuto" name="itemIdAuto1" #itemIdAuto1="ngModel" size="15" 
[suggestions]="filteredItemIdAutoSingle" (completeMethod)= "itemIdAutoComplete($event)" field="name" 
(onSelect)="itemOnSelect(itemIdAuto)" placeholder= "Select Item Name" [minLength]="1"></p-autoComplete>

<input type="number" autocomplete="off" style="font-size:12px" class="form-control" name="qty"
[(ngModel)]="model.qty" #qty="ngModel">

TypeScript:打字稿:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

export class GridFormComponent implements OnInit {

constructor() {
}

ngOnInit() {
}
@ViewChild('aForm') aForm: ElementRef;

itemOnSelect(item) {        
    this.aForm.nativeElement['qty'].focus();
    }
}

look at this link stackblitz看看这个链接stackblitz

Hope it will help you,let me know if have any query希望对你有帮助,如有疑问请告诉我

thanks谢谢

I am adding another answer as per your last comment look at below link and let me know if you found any issue.我正在根据您的最后一条评论添加另一个答案,请查看下面的链接,如果您发现任何问题,请告诉我。

one more thing to focus on element i have used jquery so please kindly keep note it.还有一件事要关注元素,我使用过 jquery,所以请注意它。

stackblitz闪电战

thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM