我有一个5表格的申请表,使用所有常用的模型,但在表格上,我希望表格可以提交,而无需实际点击"提交"按钮.

我知道这通常就像给我的按钮元素添加type=submit一样简单,但它似乎根本不起作用.

我真的不想调用onclick函数只是为了让它工作.有人能告诉我我可能遗漏了什么吗.

<form (submit)="search(ref, id, forename, surname, postcode)" action="#">
  <mat-card>
    <mat-card-title class="firstCard">Investor/Adviser search</mat-card-title>
    <mat-card-content>
      <p *ngIf="this.noCriteria" class="errorMessage">Please enter search criteria.</p>
      <p *ngIf="this.notFound" class="errorMessage">No investor's or adviser's found.</p>
        <mat-form-field>
          <input matInput id="invReference" placeholder="Investor/Adviser reference (e.g. SCC/AJBS)" #ref>
        </mat-form-field>
        <mat-form-field>
          <input matInput id="invId" placeholder="Investor/Adviser ID" type="number" #id>
        </mat-form-field>
        <mat-form-field>
          <input matInput id="invForname" placeholder="Forename" #forename>
        </mat-form-field>
        <mat-form-field>
          <input matInput id="invSurname" placeholder="Surname" #surname>
        </mat-form-field>
        <mat-form-field>
          <input matInput id="invPostcode" placeholder="Postcode" #postcode>
        </mat-form-field>
    </mat-card-content>
    <mat-card-footer>
      <button mat-raised-button type="submit" class="successButton" id="invSearch" title="Click to perform search.">Search</button>
    </mat-card-footer>
  </mat-card>
</form>

推荐答案

也可以在其周围使用一个虚拟窗体,如:

<mat-card-footer>
<form (submit)="search(ref, id, forename, surname, postcode)" action="#">
  <button mat-raised-button type="submit" class="successButton" id="invSearch" title="Click to perform search." >Search</button>
</form>
</mat-card-footer>

搜索函数必须为return false,以确保操作不会被执行

Typescript相关问答推荐

之间是否有区别:例如useEffect()React.useEffect()

material 表不渲染任何数据

在映射类型中用作索引时,TypeScrip泛型类型参数无法正常工作

学习Angular :无法读取未定义的属性(正在读取推送)

如何将CSV/TXT文件导入到服务中?

如何在处理数组时缩小几个派生类实例之间的类型范围?

获取一个TypeScrip对象,并将每个属性转换为独立对象的联合

通过泛型函数本身推断受约束的泛型参数的类型脚本问题

从route.参数获取值.订阅提供";无法读取未定义";的属性

如何在Next.js和Tailwind.css中更改悬停时的字体 colored颜色

为什么类型脚本使用接口来声明函数?他的目的是什么.

有没有一种更好的方法来存储内存中的数据,而不是在类型脚本中使用数组和基于索引的函数?

如何使用angular15取消选中位于其他组件中的复选框

如何调整项目数组,但允许权重影响顺序

类型脚本中函数重载中的类型推断问题

如何填写Partial的一些属性并让类型系统知道它?

我可以使用对象属性的名称作为对象中的字符串值吗?

数据库中的表请求返回如下日期:2023-07-20T21:39:00.000Z 我需要将此数据格式化为 dd/MM/yyyy HH:mm

覆盖高阶组件中的 prop 时的泛型推理

当并非所有歧视值都已知时,如何缩小受歧视联盟的范围?