Angular dynamic ng-model name

无人久伴 提交于 2019-12-11 19:57:38

问题


<div class="pw-form-control-text" id="disclosureQuestionsPrepopulate" name="disclosureQuestionsPrepopulate"  ng-repeat="type in (prepopulatingFieldData|prepopulateValue:'c2a39346-9e95-e411-bd87-00155d005107')" >

<div >
<input name="{{type.Id}}" ng-model="formData.disclosureQuestionsPrepopulate"($index + 1) ng-click="option.selected = true" type="radio" value=true >Yes</input>

</input>

here what I want to do is my ng-model name should be like this

formData.disclosureQuestionsPrepopulate1", formData.disclosureQuestionsPrepopulate2

like that but it doesnt work. Can someone help me?


回答1:


It should use [] to assign create a array for ng-model variable & also Value attribute should be ng-value to ensure binding with check box

HTML

<input ng-attr-name="{{type.Id}}" 
ng-model="formData['disclosureQuestionsPrepopulate'+($index + 1)]" 
ng-click="option.selected = true" type="radio" ng-value="true"/>Yes


来源:https://stackoverflow.com/questions/28667366/angular-dynamic-ng-model-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!