Creating dynamic ng-model with angular

1

I need to create the name of a model dynamically, but at the time of creating the angle obj does not accept that I try to create the obj name dynamically. Has anyone done this or do you know how to proceed?

  

The problem is occurring in the data-ng-model, I wanted to create an object named form with all its attributes dynamically.

The HTML example below

<div data-ng-repeat="campos in lista">
      <div data-ng-switch="campo.type">
          <div data-ng-switch-when="text">
               <label data-ng-if="campo.label">{{campo.label}}</label>
               <input type="text" name="{{campo.name}}" placeholder="{{campo.placeholder}}" data-ng-model="form.{{campo.name}}" />
          </div>
      </div>
</div>
    
asked by anonymous 02.04.2015 / 14:33

1 answer

4

Instead of using form.{{campo.name}} , use form[campo.name] .

For the rest, I see no problems.

    
02.04.2015 / 14:44