0

我有这样的表格

<form name="job" ng-submit="createJob(job,job_)" novalidate>

<!-- some other code -->

<!-- add new requirement to job_.requirement array on-enter --> 
<input type="text" class="form-control" ng-model="requirement" ui-keypress="{13:'addRequirement(job_)'}">

<!-- display requirements  -->

<ul>
    <li ng-repeat="requirement in job_.requirement track by $index" >{{requirement.name}}</li>
</ul>

<!-- submit entire form  -->
<button type="submit">Create Job</button>

</form>

因为每当我输入新要求时,都会使用ui-keypress(在按键上添加新要求=> 13)提交表单。ng-sumbit我有什么方法可以摆脱它?

创建了一个演示小提琴

4

1 回答 1

0

您可以使用 ng-keyup 单击输入按钮提交表单

<form name="job" ng-submit="createJob(job,job_)" ng-keyup="$event.keyCode == 13  && createJob(job,job_);" novalidate>

<!-- some other code -->

<!-- add new requirement to job_.requirement array on-enter --> 
<input type="text" class="form-control" ng-model="requirement" ui-keypress="{13:'addRequirement(job_)'}">

<!-- display requirements  -->

<ul>
    <li ng-repeat="requirement in job_.requirement track by $index" >{{requirement.name}}</li>
</ul>

<!-- submit entire form  -->
<button type="submit">Create Job</button>

</form> 
于 2017-01-21T12:48:36.093 回答