如何通过Angular中的输入字段将数值传递给函数?

时间:2013-12-06 12:51:16

标签: angularjs

我想在他们旁边列出他们的价格和数量字段的产品列表,我希望用户能够将数字传递到数量输入字段,并查看调整后的价格,所以我来了这样的事情:

    <li ng-repeat="product in products">
      {{product.price}} - quantity: <input type="text" value="1" ng-model="prodQuantity"> - {{priceTotalProducts(prodQuantity)}}
    </li>

这肯定不起作用。 请指出我正确的方向!

1 个答案:

答案 0 :(得分:1)

Here is a plunker展示了一种可能的解决方案。

我稍微更改了标记,以便计算总计的函数占用整个产品,输入绑定到quantity的{​​{1}}属性:

product

这是控制器:

<body ng-controller="Ctrl">
    <ul>
        <li ng-repeat="product in products">
            {{product.price}} - quantity: <input type="text" value="1" ng-model="product.quantity" />
         - {{priceTotalProducts(product)}}
        </li>
    </ul>
</body>
相关问题