【发布时间】:2016-09-10 00:39:31
【问题描述】:
我正在尝试将使用 .Net MVC 的表单转换为使用 Angular。我正在尝试使用 ng-repeat 在表单中生成输入字段。这是按预期工作的。但是,我需要选择与文本输入字段混合的字段。
如何使用 ng-repeat 在一个表单中混合文本字段和选择字段?甚至可能吗?我也是 Angular 的新手。此代码只是一个非常简单的示例,将被清理并正确构建。
<div ng-app>
<div ng-init="profiles = [
{id: 'first-name', label: 'First Name', type: 'text'},
{id: 'middle-name', label: 'Middle Name', type: 'text'},
{id: 'last-name', label: 'Last Address', type: 'text'},
{id: 'suffix', label: 'Suffix', type: 'text'},
{id: 'social-security-number', label: 'Social Security Number', type: 'text'},
{id: 'DateOfBirth1', label: 'Date of Birth', class: 'datePicker hasDatepicker valid', type: 'text'},
{id: 'years-in-school', label: 'Years in School', type: 'text'},
{id: 'marital-status', label: 'Marital Status', type: 'select'}
]">
<h2>Borrowers Information</h2>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<div ng-repeat="profile in profiles" class="control-group col-md-3">
<label class="control-label" for="{{profile.id}}">{{profile.label}}</label>
<div class="controls">
<input data-val="true" data-val-required="Please enter a valid first name." id="{{profile.id}}" name="{{profile.id}}" value="" type="{{profile.type}}" class="{{profile.class}}">
</div>
</div>
</div>
</div>
<script>
【问题讨论】:
标签: javascript .net angularjs asp.net-mvc