仅在选择单选按钮时添加数字

时间:2015-07-22 17:21:21

标签: javascript angularjs

如果用户选择value = "serfeeadd"单选按钮,我想根据单选按钮选择为总金额添加一个数字,所以我需要检查它,得到它并将其添加到总数中但我可以'弄清楚为什么它不起作用,但是当我删除scope = this并且仅直接使用$scope它有点起作用时,我只需要赋值给变量。

我正在尝试构建一个magento腕带设计师应用程序,所有内容都只是坚持使用这部分。

代码已经过修改,可以为您提供概述,让您了解更多信息。



var app = angular.module('wdWristbandDesigner', []);
  app.controller("fontCtrl", MainController);

function MainController($scope){

  //scope
  var scope = this;
  
  scope.foo = function(){
    if (scope.serialisationFeeCheck == 'serfeeadd') {
    scope.serialisationFee = 10;
    console.log(scope.serialisationFeeCheck);
  }
  else {
    scope.serialisationFee = 0;
  };
  }

};

<section class="wd-section" ng-controller="fontCtrl as fs">
  <input type="radio" name="serialno" data-ng-model="serialisationFeeCheck" value="no"  >No
            <br>
            <input type="radio" name="serialno" data-ng-model="serialisationFeeCheck" value="our">Yes(Our Choice)
            <br>
            <input type="radio"  id="chk" name="serialno" data-ng-model="serialisationFeeCheck" value="serfeeadd" >Yes(Your Choice)
<button typ="button" ng-click="foo()" >click</button>
  </section>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

ng-click应为fs.foo(),并且所有ng-model都需要应用fs对象。