-1

My question is about generating dynamic html content with ng-repeat that contains multiple ng-model instances stored in an array.

But I get a syntax error for {{ in ng-model.

Is it possible somehow?

<div class="col-xs-12 col-md-12 col-sm-12 col-lg-12" ng-repeat="(key, antecedente) in antecedentes" >    
    <div class="form-group">
    <label class="col-md-3">{{antecedente.name}}</label>
        <div class="col-md-1"> Si&nbsp;<input ng-model="historia.antecedentes[{{key}}].seleccionado" type="radio" value="S"></div>
        <div class="col-md-1"> No&nbsp;<input ng-model="historia.antecedentes[{{key}}].seleccionado" type="radio" value="N"></div>
        <div class="col-md-2">Observaciones </div>
        <div class="col-md-5"><input ng-model="historia.antecedentes[{{key}}].observacion" class="form-control"  type="text" value=""></div>
    </div>
</div>
SomethingDark
  • 13,229
  • 5
  • 50
  • 55
Stivenson
  • 23
  • 8

2 Answers2

2

you dont need curly braces around key, ng-model evaluates the expression/variable itself

 ng-model="historia.antecedentes[key].seleccionado"
A.B
  • 20,110
  • 3
  • 37
  • 71
  • Angular is brilliant. Thank you very much...friend !! [A.B](http://stackoverflow.com/users/3680831/a-b) – Stivenson Mar 21 '15 at 08:13
0

Everything you have a tag with ng in front of it, you don't have to have any curly braces, ever (except with ngSrc, wich whole purpose is to use curly braces inside a src). That's a good memory rule I think.

petur
  • 1,366
  • 3
  • 21
  • 42
  • Yes, I know. Should've specified that. However, the ngSrc directive is special since it solves a problem with having curlybraces inside the src tag. So if you use ngSrc, you should know you CAN use curly braces inside there. It is, however, not necessary. – petur Mar 21 '15 at 08:17
  • 1
    yes you can re arrange the words to clearify, still it's okay for us as we know things but can confuse beginners, just saying :) – A.B Mar 21 '15 at 08:19