Hello, 

i am trying to make a simple calculator, but have some issues. So i can not 
fill the input value by keyboard. it doesnt work correctly. There is like 
two differents field in input.

I hope someone can help me figure out whats wrong.
<div class="container" ng-controller="calcCtrl">



 <div class="content">

 

 <br>

 <input type="text" ng-model="total"></input><br>

 

    <button class="btn_calc" ng-click='add(7)'>7</button>

    <button class="btn_calc"  ng-click='add(8)'>8</button>

    <button class="btn_calc" ng-click='add(9)'>9</button>

    <button class="btn_calc" ng-click='add("/")'>/</button>

    <br>

    <button class="btn_calc" ng-click='add(4)'>4</button>

    <button class="btn_calc" ng-click='add(5)'>5</button>

    <button class="btn_calc" ng-click='add(6)'>6</button>

    <button class="btn_calc" ng-click='add("*")'>*</button>

    <br>

    <button class="btn_calc" ng-click='add(1)'>1</button></td>

    <button class="btn_calc" ng-click='add(2)'>2</button></td>

    <button class="btn_calc" ng-click='add(3)'>3</button></td>

    <button class="btn_calc" ng-click='add("-")'>-</button></td>

    <br>

    <button class="btn_calc" ng-click='add(0)'>0</button>

    <button class="btn_calc" ng-click='add(".")'>.</button>

    <button class="btn_calc" ng-click='add("+")'>+</button>

    <button class="btn_calc" ng-click="eval()">=</button>

    <br>

    <button class="btn_clear" ng-click="remove()">CLEAR</button>

    

 </div>

</div>


app.controller('calcCtrl',  function($scope) {



    $scope.formula = ['0'];

 $scope.add = function(item) {

    if ($scope.formula == '0') $scope.formula = [item];

    else $scope.formula.push(item);

    $scope.total = $scope.formula.join('');

};

    $scope.remove = function() {

    $scope.formula.pop();

    if($scope.formula.length == 0) $scope.formula = ['0'];

    $scope.total = $scope.formula.join('');

};

    $scope.eval = function() {

    var result = eval($scope.formula.join(''));

    $scope.formula = [result];

    $scope.total = $scope.formula.join('');

};

  



    });



-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to