I am creating a small price calculator on my website where the user selects the services he needs. As he selects his services the price is updated accordingly.
ANGULAR
$scope.price = 0;
HTML
<h4> What features would you like? </h4>
<input type="checkbox" value="feature 1" ng-checked="price = price + 5">
<input type="checkbox" value="feature 2" ng-checked="price = price + 25">
<input type="checkbox" value="feature 3" ng-checked="price = price + 50">
<h4> Would you like your project to include X? </h4>
<input type="radio" name="feature" value="yes" ng-checked="price = price + 10">
<input type="radio" name="feature" value="no" selected>
<h5> We think your project will cost around ${{price}} </h5>
As you can see from the example, once the user clicks an option, it will add a value to the price variable, but will take the value away if deselected. Ng-checked doesn't work though. How can I do this?
Thanks!
ng-checkeddocs.angularjs.org/api/ng/directive/ngChecked Hence the expression should be conditional.