如何在角度js中执行if操作取决于选择了哪个单选按钮?

时间:2017-07-27 07:58:38

标签: javascript jquery angularjs

我的项目中有两个单选按钮。根据选择的单选按钮,我需要向后端发送命令。我尝试了很多ng - ****如果其他操作对我没用。请帮助我同样的



$scope.compareReference = function() {
  if($scope.radoreslt is checked){
   	 Factory.send("GetAddonData(CompareBkcXml,$scope.filetxt,File)");
   }else{
	 Factory.send("GetAddonData(CompareBkcXml,$scope.filetxt,All)");
   } 
};

    <div id="collapseTwo" class="panel-collapse collapse" aria-expanded="false">
    <div class="box-body">
        <div class="input-group">
            <div class="form-group">
                <label>
                    <input type="radio" ng-model="radoreslt" name="r1" checked>Compare with File Specific
                </label>
                <label>
                    <input type="radio" ng-model="radoreslt" name="r1">Compare All
                </label>
            </div>

            <input type="text" class="form-control" ng-model="filetxt">
            <span class="input-group-addon"><input type="File"  onchange="copyMe(this)" ></span>
        </div>
        <br/>
        <button class="btn btn-primary btn-sm" ng-click="compareReference()">Compare</button>
    </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您应始终将值属性传递给每个单选按钮,因为绑定模型仅使用该值更新。这是一个例子。

<input type="radio" ng-model="radoreslt" name="r1"  value="compareWithSpecific">
<input type="radio" ng-model="radoreslt" name="r1"  value="compareAll">

<强> JS

 $scope.compareReference = function() {
        if ($scope.radoreslt == "compareWithSpecific") {
            Factory.send("GetAddonData(CompareBkcXml,$scope.filetxt,File)");
        } else {
            Factory.send("GetAddonData(CompareBkcXml,$scope.filetxt,All)");
        }
    };