0

I'm a newbie in angularjs so I tried to create my first simple application. I want to create dynamic radio buttons from json(at this point everything works fine), so I tried to bind the radio buttons with a new model to grab their values, but I don't understand how to bind a model from variables. This is my code:

<div ng-controller="TestCtrl">
   <h1> {{corso._name}}</h1>
   <div ng-repeat="(key,value) in corso._domande">
     <h3>{{value._domanda}}</h3> 
      <form name="value._id" ng-repeat="ris in value._risposte">
        /*I wanto to use somothing like result.key*/
        <input  type="{{value._type}}" ng-model="?????????" /> 
        {{ris}}
      </form>
   </div>
</div>

and js:

function TestCtrl($scope) {
$scope.result={};
  $scope.corso={
  "_name":"Corso X",
  "_domande":{
        "1":{ "_domanda" : "Che colore ha la birra?",
          "_id":"1",
          "_type":"radio",
          "_risposte" : ["giallo","rosso","blu"],
          "_risportaEsatta" : "giallo"
        },
       "2":{ "_domanda" : "Che colore ha l'acqua?",
          "_id":"2",
          "_type":"checkbox",
          "_risposte" : ["giallo","rosso","blu"],
          "_risportaEsatta" : "giallo"
       }
  }
  };
 };

http://jsfiddle.net/4zq1ydjs/3/

fer
  • 1,016
  • 1
  • 10
  • 20
Sceik
  • 275
  • 1
  • 3
  • 13
  • You are creating a different form per radio button, is that intended? See this very closed SO question: http://stackoverflow.com/questions/24248098/angularjs-dynamic-form-from-json-data-different-types – fer Nov 29 '14 at 17:33
  • Yes, it was only for trying, I will change it with a fieldset. However my problem isn't displaying the form elements but binding them with a model to get their value. – Sceik Dec 01 '14 at 11:35

0 Answers0