I am looking for the best way to swap between if statements using radio buttons. I am doing a calculation in my controller, that uses the radio buttons to determine which calculation to do, so if you select Radio1 it will do Calc1, and if you select Radio2 it will do Calc2. But you must be able to swap between Calc1 and Calc2 as you please, and not be limited to one or the other per page refresh.
Here is an example of what I am looking for, using my current controller. Note My firm isn't using $Scope directly, we use vm. which is the equivalent to $Scope for us.
if (vm.isFemale) {
return Math.round((66 + (6.23 * vm.weight) + (12.7 * ((vm.feet * 12) + vm.inches)) - (6.8 * vm.age)) * vm.dropdown);
}
if (vm.isMale) {
return Math.round((655 + (4.35 * vm.weight) + (4.7 * ((vm.feet * 12) + vm.inches)) - (4.7 * vm.age))) * vm.dropdown;
}
if (output == null || output == "NaN")
return;
}
I am new to AngularJS, i looked in the API and some forms, but I couldn't find anything that seemed to be useful to my current situation, If I overlooked something, please point me in the right direction.
EDIT
This is how I am defining the radio buttons in the HTML pages:
<label for="sex">Sex: </label>
<label>
<input type="radio" ng-model="vm.isMale" />Male
<input type="radio" ng-model="vm.isFemale" />Female
</label>
66instead of655) instead of the entire calculation.vmisn't "equivalent" to$scope; even when using the ControllerAs pattern,$scopestill exists, andvmis actually a child object of it, i.e.$scope.vm.myProperty. therefore, it is still important for us to see how these buttons are defined in the HTML.