我正在使用 Angular 表达式作为文本框中的值来执行一些操作
`<tr>
<td><input type="text" ng-model="product.costPrice" required
placeholder=" product Cost" class="form- control" > <span
class="help-block"></span></td>
</tr>
<tr>
<td><label>Profit</label></td></tr>
<tr>
<td><input type="text" ng-model="Product.profit" required
placeholder=" Profit in %" class="form-control"> <span
class="help-block"></span></td>
</tr>
<tr>
<td><label>price</label></td></tr>
<tr>
<td><input type="text" value="{{product.costPrice * Product.profit}}" ng-model="Product.sellingPrice" required
placeholder=" selling price" class="form-control"> <span
class="help-block"></span></td>
</tr>
<tr>
<td>
<p>Expense on Books : {{product.costPrice * Product.profit}} Rs</p>
</td>
</tr>`
表达式根本不起作用,即使它在 <p></p>
中起作用标记我做错了什么??
最佳答案
你可以创建一个函数(在函数内部你可以编写并返回你的表达式):
$scope.myExpression = function(){
return $scope.myVar + "hello";//this is your expression function
}
并使用 ng-value
<input ng-value="myExpression()">
工作代码here
关于javascript - 文本框中的 Angular 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41197422/