【发布时间】: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