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

huangapple go评论85阅读模式
英文:

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>

如果您需要进一步的帮助,请随时提出。

英文:

I am using ngPrime autocomplete to fetch data from service. My requirement is to fetch text written in autocomplete at any instance on button click. I tried to fetch value using getElementById.value in the component but it is returning undefined.

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

答案1

得分: 0

  • 基于您的评论:

    • 这是另一个组件.html文件中的代码<app-data>可重用的自动完成组件</app-data> <button (click)="filter(自动完成值)">搜索联系人</button> 在这里,我想获取自动完成的值。我该如何实现它?
  • 您需要通过使用input和output检测器来处理此问题。您可以使用输入装饰器将值从父组件传递给子组件。您可以使用输出(事件发射器)来在父组件中获取子组件的值

英文:

Based on your comment:

  • This is the code in another component.html file <app-data>Resuable autocompletelte component</app-data> <button (click)="filter(autocomplete value)">Search Contact</button> Here, I want to fetch autocomplete value. How I can achieve it?

>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

huangapple
  • 本文由 发表于 2020年1月4日 12:35:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/59587921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定