我想知道是否可以做这样的事情。
在控制器中。
$rootScope.liveIn = "liveInCareHome";
HTML代码段
ng-model='housingDetails + "." + liveIn'
这样输入的值将存储在housingDetails中。即具有ng-model="'housingDetails.liveInCareHome'"
完整的HTML
<ng-form id="housingDetailsngform" name="housingDetailsngform">
<section id="housingDetails" class="full-form">
<div class="question">
<div class="question-input ">
<select required class="form-control" name="{{liveIn}}" ng-model='housingDetails + "." + liveIn'>
<option value="co-ownership">Co-ownership</option>
<option value="crownTenant">Crown tenant</option>
</select>
</div>
</div>
</section>
</ng-form>
虽然我已经在线查看,但如果存在,我似乎无法获得该版本的工作版本。任何其他建议也欢迎。
答案 0 :(得分:1)
像这些
声明你的数据ng模型HTML
<select ng-model="housingDetails[liveIn]">
控制器
$rootScope.liveIn = "liveInCareHome";