我是angularjs的新手,所以我尝试创建我的第一个简单应用程序。 我想从json创建动态单选按钮(此时一切正常),所以我尝试将单选按钮与新模型绑定以获取它们的值,但我不明白如何从变量绑定模型。 这是我的代码:
<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>
和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"
}
}
};
};