javascript - angular form set variable equal expression -
i have following object:
$scope.module.discount = [{ licences: 0, discountpercentage: 0, new_value_pr_licence: 0 }]
and following simple form:
<div class="form-group"> <label>pris pr licens</label> <div class="input-group m-b"> <input type="number" class="form-control" ng-model="module.price_pr_licence"> <span class="input-group-addon">kr</span> </div> </div> <div class="col-xs-12"> <table> <thead> <th>licenser</th> <th>% rabat</th> <th>ny pris pr stk</th> </thead> <tbody> <tr ng-repeat="discount in module.discount"> <td> <input class="form-control" ng-model="discount.licences" type="number" required=""> </td> <td> <input class="form-control" type="number" ng-model="discount.discountpercentage" required=""> </td> <td> <button class="btn btn-sm btn-default">{{module.price_pr_licence * (1-(discount.discountpercentage / 100))}}</button> </td> </tr> </tbody> </table> </div>
as can see button's value expression:
{{module.price_pr_licence * (1-(discount.discountpercentage / 100))}}
now wish set:
discount.new_value_pr_licence = module.price_pr_licence * (1-(discount.discountpercentage / 100))
however im not quite sure how that.
how bind variable such expression?
you can go computed property (via accessor) keep things clean , spare angular's expression parser not support full js expression trees..
$scope.module.discount = [{ licences: 0, discountpercentage: 0, new_value_pr_licence: 0, discountedprice() { return ($scope.module.somevalue + this.someothervalue / 100) } }]
then later on reference
{{discount.discountedprice}}
fiddle:
Comments
Post a Comment