【发布时间】:2017-01-30 23:36:21
【问题描述】:
我的 js/控制器中有一系列作业。数组中的每个job对象都有jobName、company、city等属性。是否可以通过提交带有属性输入的表单使其成为job对象,然后将其推送到控制器中的jobs数组中?
例如,我有一个表单,我输入了 Software Developer, StackOverflow, NY。我可以将表单包装到具有正确属性的对象中,然后将其传递到控制器中的作业数组中以在视图上查看它吗?
到目前为止,这是我的表单代码...
<form name="jobForm" ng-submit="list.addJob(jobForm)">
<div class="form-group" id="test">
<label>Job Name:</label>
<input ng-model="jobName" type="text"/>
</div>
<div>
<label>Company:</label>
<input ng-model="companyDescription" type="text"/>
<div><button type="submit">Enter job entry</div>
</div>
<!-- this is where the live preview is. ng-model in the input binds it to these values -->
<blockquote>
<h4><u>Live Preview</u></h4>
<b>Job Name:</b> {{jobName}}
<div><b>Company:</b>{{companyDescription}}</div>
</blockquote>
</form>
所以我想创建一个 JOB 对象,使用 jobName 和 companyDescription 的输入作为对象的名称和公司属性。我怎样才能做到这一点?或者我使用了错误的方法。感谢您的帮助!
【问题讨论】:
标签: javascript html angularjs forms object