我正在尝试使用Angular构建一个购物车列表。
对于每个产品,我希望能够在用户输入数量时添加到我的orderForm。如果数量为nil或0,则不应出现在products数组中。
以下是我试图收到的参数:
{"order": {"products": [{"id":2, "quantity":"45"}, {"id":2, "quantity":"45"}], "contact_name": "Acme Inc."} }
<div data-ng-controller="MyController">
<form id="my_form" name="my_form" action="/echo/jsonp/" method="get">
<label for="{{ orderForm.contact_name }}">Your Name:</label>
<input type="text" data-ng-model="orderForm.contact_name">
<div ng-repeat="product in products">
<label for="{{ product.name }}">{{ product.name }}:</label>
<input type="number" id="{{ product.quantity }}" data-ng-model="product.quantity" required>
</div>
<input type="submit" />
</form>
{{ orderForm }}
<!-- for each product when quantity > 0 it should return {{ id:2, quantity:X }} -->
<!-- form should exclude products where quantity is nil }} -->
<!-- {"order": {"products": [{"id":2, "quantity":"45"}, {"id":2, "quantity":"45"}], "contact_name": "Acme Inc."} } -->
</div>