R
R
Roman Koff2016-02-09 16:45:08
Angular
Roman Koff, 2016-02-09 16:45:08

How to generate sum using AngularJS?

Started learning AngularJS. I want to start with a simple example. On sites, acquaintance begins with more complex examples, tell me how to do a simple thing:
There is a form with fields on it:

<input ng-model="Price" id="Price" name="Price" type="hidden" value="1500" />
Цена: {{Price}}<br />
Количество: <input ng-model="Count" id="Count" name="Count" type="text" value="0" /><br />
Сумма: {{Count * Price}} руб<input id="Amount" name="Amount" type="hidden" value="0" /><br />

The price is set initially (obtained from the hidden input.Price field). When entering the amount, the amount is automatically calculated and placed in the hidden input.Amount field.
It's not clear how to set the initial data (AngularJS zeros out the value of connected fields), how to multiply AJS fields, and how to put the value in the input field

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2016-02-09
@Zarinov

You can set values ​​through ng-init="Price=1500", Amount can be "beaten" in several ways, if without a controller, then you can try ng-model for Amount and update it on an ng-change (or ng-keyup) event to do the calculation : ng-change="Amount=Price*Count"
Here's an Angular Light example: jsfiddle.net/lega911/f66ep40p

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question