javascript - 文本框中的 Angular 表达式

标签 javascript html angularjs

我正在使用 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/

相关文章:

html - 在html中将幻灯片放映向左移动

javascript - 如何在 Angular JS 中进行嵌套分组

javascript - CSS 优化以自动更改类名

javascript - d3.js v4 minimap 或如何在两个元素上共享缩放?

javascript - 在 Javascript 中将 HTML 文件内容转换为字符串

jquery - 放置一个 div,使其看起来位于 mainwrapper (980px) 之外

jquery - 切换在表外而不是表内工作

javascript - 链接 promise 导致未定义

javascript - 如何在 AngularJS 中显示和隐藏代码块

javascript - 以编程方式将预设传递给 babel