简体   繁体   中英

AngularJS ng-model with collections

Newbie question.

I have a model defined like this:

 $scope.model = some json like below:

"ApplicantNames":[
  "Primary applicant : Ian Vink",
  "Joint applicant : Sally Ride"
]

I have 2 input boxes , one for each applicant, that I wish to bind via ng-model, but I don't know the naming structure

 <input ng-model="model.ApplicantNames[0]????">
 <input ng-model="model.ApplicantNames[1]????">

Note these are actually complex Kendo controls bound in MVC so I am not using ng-looping to create them.

Your suspicions are correct.

If you want to bind to the elements of $scope.model.ApplicantNames and be able to edit them in the view, the "naming structure" is:

<input ng-model="model.ApplicantNames[0]" />
<input ng-model="model.ApplicantNames[1]" />

See, also, this short demo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM