如何在 Angular 6 中单击按钮时获取 Primeng 自动完成文本

How to fetch ngPrime autocomplete text on button click in Angular 6

我正在使用 ngPrime 自动完成功能从服务中获取数据。我的要求是在单击按钮时随时获取以自动完成方式编写的文本。我尝试在组件中使用 getElementById.value 获取值,但它返回 undefined

  <p-autoComplete [(ngModel)]="contact" [suggestions]="contactList.TaxEntities" (completeMethod)="filterContact($event)"
        field="TaxEntityName" [size]="30" placeholder="Search Contact" [minLength]="1" appendTo="body" id="auto">
        <ng-template let-selectedItem pTemplate="item">
            <div class="ui-helper-clearfix">
                {{selectedItem.TaxEntityName}}, {{selectedItem.TaxEntityABN}}
            </div>
        </ng-template>
    </p-autoComplete>

根据您的评论:

  • 这是另一个 component.html 文件中的代码 Resuable autocompletelte component Search Contact Here,我想获取自动完成值。我该如何实现?

You needs to handle this by using input and output detectors. You can pass the values to child component from parent component by using input decorator. you can use output(event emitter) to get the child component values in parent component