How can I increment and decrement a value in angularjs?

angularjs, javascript

Solution

Simply this should work,

<div>
    <button ng-click="count = count+1" ng-init="count=15">
        Increment
    </button>
    count: {{count}}

    <button ng-click="count = count - 1">
        Decrement
    </button>
<div>

Problem

I have one value initially - let's call it x. Selecting the increment button should increase "+1" to the value. If I select decrement, x should decrease by -1. However, what actually happens is that when I press the increment button, it increases +1 but if i click decrement, it decreases -2. It should only be increased/decreased by 1 value only. Also don't require continuous iteration (count++ and count--). it would be better if "count" is taken as variable inside .js file, not mentioning it in html as ng-init="count=15" . JsBin ``` <div ng-controller="CounterController"> <button ng-click="count = {{count}}+1" ng-init="count=15"> Increment </button> count: {{count}} <button ng-click="count = {{(count) - 1}}"> Decrement </button> <div> ```

Original source