想要将gobal过滤器放在primeNg表组件之外

问题描述

我正在使用primneNg,现在想添加全局过滤器,但是问题是我需要将此过滤器添加到另一个组件中。这两个组件都嵌套在其他组件中。

我所做的是使用@ViewChild('table') table: TableComponent;引用了表组件,并将其传递给child并做了table.filterGlobal($event.target.value,'contains')我收到“未定义标识符'filterGlobal'”错误

filter.compononent.html

<input (input)="table.filterGlobal($event.target.value,'contains')" pInputText type="text"  placeholder="Search..." />

filter.component.ts

@ViewChild('table') table: TableComponent;

table.compoent.html(应用程序表)

<p-table #table value]="data" sortMode="single" reorderableColumns="true" scrollable="true" scrollHeight="350px" [(selection)]="selectedItems">

dynamic-listing.comoponent.html

<app-filter></app-filter>
<app-table></app-table>
这些过滤器和表组件中的

都在另一个组件(dynamic-lising.component.html)中被调用。该组件也被许多其他组件调用

解决方法

必须在过滤器内定义表组件,以便使其可访问。 您可以使用动态列表组件中的viewchild访问表。 您可以尝试将组件包含在filter.component.html