Angular dynamic ng-model name

2019-09-01 08:07发布

问题:

<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