我有以下对象:
<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>
以下简单形式:
{{module.price_pr_licence * (1-(discount.discountPercentage / 100))}}
你可以看到按钮的值是一个表达式:
discount.new_value_pr_licence = module.price_pr_licence * (1-(discount.discountPercentage / 100))
现在我想设置:
int search_close_btnId = android.support.v7.appcompat.R.id.search_close_btn;
ImageView search_close_btn = (ImageView) searchView.findViewById(search_close_btnId);
search_close_btn.setImageResource(R.drawable.ic_close_search);
但我不太清楚该怎么做。
如何将变量绑定到这样的表达式?
答案 0 :(得分:1)
你可以使用计算属性(通过访问器)来保持干净,还可以使用不支持完整JS表达式树的备用角度表达式解析器。
$scope.module.discount = [{
licences: 0,
discountPercentage: 0,
new_value_pr_licence: 0,
get discountedPrice() {
return ($scope.module.someValue + this.someOtherValue / 100)
}
}]
稍后您只需将其引用为
{{discount.discountedPrice}}
小提琴: