How to generates dynamically ng-model=“my_{{$index}}” with ng-repeat in AngularJS?

前端 未结 6 648
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 08:16

I would like to ask you if you can give me a hand on this.

I have created a jsfiddle with my problem here. I need to generate dynamically some inputs with ng-model i

6条回答
  •  孤街浪徒
    2020-11-29 08:42

    I did elaborate my answer from pkozlowski's and try to generate a dynamic form, with dynamic ng-model:

    But first, we need to define the 'human' scope inside our controller

    $scope.human= {};
    

    And then, on submission we will have the data like this (depending on how much field is generated):

    var name = human.adult[i].name;
    var sex = human.adult[i].sex;
    var age = human.adult[i].age;
    

    It's pretty straightforward and I hope my answer helps.

提交回复
热议问题