以角度4访问多个输入属性

时间:2018-03-15 07:17:01

标签: angular

您好我已经在互联网上搜索但找不到这个问题的答案,所以我在一个页面上有一个巨大的表格,该表格有大约30-40列,某些列有基于输入的搜索过滤器喜欢这张图片:

Table structure image

和输入定义如下:

<th><input type="text" appCustomSearch class="form-control width-0x" name="last_name" [searchTab]="'social'"/></th>

所以基本上我需要使用输入字段来获取3/4值:

  • 要搜索的表格
  • 该表中的列名称
  • 要搜索的值。

但我找不到一种方法可以轻松动态地做到这一点我也尝试编写自己的指令,但它只适用于单个输入,我希望用户填写他想要的所有输入字段,然后再按钮单击它应该过滤结果。 可以通过表单访问输入但无法访问数据属性甚至输入字段的“名称”,请帮助我。

1 个答案:

答案 0 :(得分:0)

您可以使用ViewChildren装饰器。首先为您的输入创建自定义组件。

<input 
  type="text"
  appCustomSearch
  class="form-control width-0x"
  name="last_name"
  [searchTab]="'social'"
  #customSearch
/>

在您的TS中

@ViewChildren(CustomSearchDirective) inputs: QueryList<CustomSearchDirective>;

这将给出具有属性appCustomSearch的所有输入的列表。