如何在提交表单上传递更改数据切换值

时间:2018-05-18 07:13:42

标签: angularjs

以下是我的代码

<form class="form-horizontal" name="addForm.REFForm" role="form" ng-submit="saveInfo(currentPlayer.Player,playerinfo.StateLevel)" novalidate>
    <div class="btn-group" data-toggle="buttons">
        <label class="btn btnProfileDefault" ng-class="{'true':'active', 'false':''}[playerinfo.StateLevel]">
            <input type="radio" value="true" name="StateLevel" ng-model="playerinfo.StateLevel">
            Yes
        </label>
        <label class="btn btnProfileDefault" ng-class="{'true':'', 'false':'active'}[playerinfo.StateLevel]">
            <input type="radio" value ="false" name="StateLevel" ng-model="playerinfo.StateLevel">
            No
        </label>
     </div>
</form>

如果有人点击是,我想将playerinfo.StateLevel的更新值发送到SaveInfo功能,但我无法执行此操作playerinfo.StateLevel值未更新数据切换是否存在无论如何。

1 个答案:

答案 0 :(得分:0)

因为当您单击是或否时,saveInfo()中的ng-submit功能将无法触发。您应该添加如下所示的ng-change或添加提交按钮。

<div class="btn-group" data-toggle="buttons">
    <label class="btn btnProfileDefault" ng-class="{'true':'active', 'false':''}[playerinfo.StateLevel]">
        <input type="radio" value="true" name="StateLevel" ng-model="playerinfo.StateLevel" ng-change="clicked(currentPlayer.Player, playerinfo.StateLevel)"> Yes
    </label>
    <label class="btn btnProfileDefault" ng-class="{'true':'', 'false':'active'}[playerinfo.StateLevel]">
        <input type="radio" value="false" name="StateLevel" ng-model="playerinfo.StateLevel" ng-change="clicked(currentPlayer.Player, playerinfo.StateLevel)"> No
    </label>
</div>