Сообщение от destus
|
а так?
ng-value="{{formula.join('')}}"
|
неа, в поле то писать могу, но калькулятор не работает:
<div class="container" ng-controller="calcCtrl">
<div class="content">
<br>
<input type="text" ng-value="{{formula.join('')}}">
<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.remove = function() {
$scope.formula.pop();
if($scope.formula.length == 0) $scope.formula = ['0'];
};
$scope.eval = function() {
var result = eval($scope.formula.join(''));
$scope.formula = [result];
};
});