我正在尝试创建一项调查。代码如下所示:
<form ng-submit="passEngineer(engineer)">
<input type="radio" ng-model="engineer" ng-required="!engineer">Default
<input type="radio" ng-model="engineer" ng-required="!engineer">Custom
<input type="text" ng-model="engineer" ng-required="!engineer">
</form>
如果选择First
,它会毫无问题地通过它。如果选择了Second
,它应该传递在third
输入中输入的值。我怎样才能做到这一点?如果选择了第二个输入,则必须传递第三个输入中的值。尝试过很多方法,无法弄清楚。
答案 0 :(得分:0)
我认为你需要分清你应用ng-model
的方式。您可以在控制器中创建一个engineer
对象,然后像这样更改标记:
<form ng-submit="passEngineer(engineer)">
<input name="engineer" type="radio" ng-model="engineer.isDefault">Default
<input name="engineer" type="radio" ng-model="engineer.isCustom">Custom
<input type="text" ng-model="engineer.customValue" ng-required="engineer.isCustom">
</form>