【问题标题】:Uncaught ReferenceError and processForm is not defined未捕获的 ReferenceError 和 processForm 未定义
【发布时间】:2018-09-19 11:21:55
【问题描述】:

如何从表单外部调用表单,我有一个有角度的表单,我正在使用引导程序 这是一个 sn-p,一个带有 ngubmit 的表单,为了节省设计,我尝试从外部调用,请问我该怎么做

   <ul class="navbar-nav">
          <li class="nav-item">
            <a class="btn btn-light"
               type="submit"
               title="Save department"
               data-toggle="tooltip"
               data-placement="bottom">
              <i class="fa fa-save"></i>
              <span class="d-none d-sm-inline" *** this is where i tried to call the form**** onclick="processForm()">Save</span></a></li>
        </ul>
      </nav>

    </header>
    <section id="department">
      <div class="container-fluid">
        <div class="row">
          <div class="col">
            <div class="card">
              <div class="card-body">
    ****this is the begining of the form 
                <form  (ngSubmit)="processForm()"    id="editFormTruck" >

                  <div class="form-group">
                    <label class="form-control-label"
                           ngFor="truckCode">Truck code</label>
                    <input type="text" name="truckCode"  class="form-control" [(ngModel)]="truck.truckCode">
                  </div>

                  <div class="form-group">
                    <label class="form-control-label"
                          ngFor="purchasedDate">purchased Date</label>
                    <input type="date" name="purchaseDate" class="form-control" [(ngModel)]="truck.purchasedDate" useValueAsDate>
                  </div>

                  <div class="form-group">
                    <label class="form-control-label"
                           ngFor="truck.description">Description</label>
                    <input type="text" name="description" class="form-control" [(ngModel)]="truck.description">
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>

【问题讨论】:

  • 所有这些 html 是否都显示在您的组件模板中?不问是否还有更多 HTML,只是确保您显示的内容都在同一个组件中,而不是以某种方式分布在多个组件中
  • 你想在这里使用 Angular 吗? onclick="processForm()" 如果是这样,你需要这样的语法:(click)="processForm()"
  • 是的,它们都在同一个组件中,你在我的表单上说我应该使用它或保存部分(我的保存按钮)
  • 您的保存按钮。使用 onclick 会使用原生 JS 点击处理程序行为,但您希望 Angular 将其连接起来,因此请使用 (click) 语法。
  • 如何将它们与 id 连接起来

标签: angular twitter-bootstrap-3 bootstrap-4


【解决方案1】:

如果您想手动提交表单,您可以获取对表单的引用并手动触发 ngSubmit 上的发射。我整理了一个simple Plunker 做它。

<span class="d-none d-sm-inline" (click)="form.ngSubmit.emit()">Save</span>

...

<form #form (ngSubmit)="processForm()" ...>...</form>

【讨论】:

  • 我有两个网址,这是一个不同的问题,但会有所帮助吗? curl -v localhost:8088/orders/ // curl -v localhost:8088/orders?start=2007-01-01&end=2008-01-01 */ 正如你所看到的他们的订单和订单过滤器,我想在我的角度应用程序中默认获取订单列表,并且还可以选择过滤日期,请问怎么办?
  • 请创建一个新问题,有人会帮助您解决问题。以这种方式寻求帮助是不合适的。
猜你喜欢
  • 2023-01-23
  • 2016-11-03
  • 2011-01-05
  • 2016-01-02
  • 2013-10-06
  • 2016-12-17
  • 1970-01-01
相关资源
最近更新 更多