Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. var myApp = angular.module('myApp', []);
  2.  
  3. myApp.controller('myController', function($scope) {
  4.  
  5.  
  6. function resetFields(){
  7. $scope.opReset=' ';
  8. }
  9.  
  10. function add(x, y) {
  11. return x + y;
  12. }
  13.  
  14. function sub(x, y) {
  15. return x - y;
  16. }
  17.  
  18. function mul(x, y) {
  19. return x * y;
  20. }
  21.  
  22. function div(x, y) {
  23. return x / y;
  24. }
  25.  
  26. function calc(op, x, y) {
  27. return $scope.operators[op](parseInt(x, 10), parseInt(y));
  28. }
  29.  
  30. $scope.operators = {
  31. '+': add,
  32. '-': sub,
  33. '*': mul,
  34. '/': div
  35. };
  36. $scope.op = '+';
  37. $scope.calc = calc;
  38.  
  39. });
  40.  
  41. <div ng-app="myApp">
  42.  
  43. <div ng-controller="myController" ng-init='isFocused=true'>
  44.  
  45. <form>
  46.  
  47. <div class="col-lg-5 col-md-8 col-sm-12 col-xs-12">
  48. <input width="100%" type="text" class="form-control" id="operand1" style="height:50px; font-size:32px" ng-model="operand1" ng-focus=' isFocused="operand1" ' value="{{opReset}}" autofocus>
  49. </div>
  50.  
  51.  
  52. <div class="col-lg-2 col-md-8 col-sm-12 col-xs-12 text-center" style="font-size:32px">
  53. {{op}}
  54. </div>
  55.  
  56.  
  57. <div class="col-lg-5 col-md-8 col-sm-12 col-xs-12">
  58. <input width="100%" type="text" class="form-control" style="height:50px; font-size:32px" ng-model="operand2" ng-focus=' isFocused="operand2" ' id="operand2" value="{{opReset}}">
  59. </div>
  60.  
  61. <script src="js/custom.js"></script>
  62.  
  63. </div>
  64.  
  65. </div>
  66.  
  67.  
  68. <div class="col-lg-5">
  69.  
  70. <div class="row">
  71.  
  72. <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 eqProps text-center">
  73. =
  74. </div>
  75.  
  76.  
  77. <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"style="font-size:32px">
  78.  
  79. {{output}}
  80.  
  81. </div>
  82.  
  83. </div>
  84.  
  85. </div>
  86.  
  87. </div>
  88.  
  89.  
  90.  
  91. <div class="row">
  92.  
  93.  
  94. <div class="col-lg-1"></div>
  95.  
  96. <div class="col-lg-7">
  97.  
  98. <div class="row">
  99.  
  100. <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1"></div>
  101. <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10">
  102. <div class="row-fluid">
  103.  
  104. <button class="btn btn-danger btn-fonts" type="reset" value="reset" ng-click=" opReset=resetFields() ">C</button>
  105. <div class="btn btn-default btn-fonts" ng-repeat="n in [0]" style="margin-left:2px" ng-click='$parent[isFocused]=$parent[isFocused]+""+n' ng-disabled='isFocused===true'>{{n}}</div>
  106. <div class="btn btn-default btn-fonts" ng-click="output=calc(op,operand1,operand2)" style="visibility:hidden">=</div>
  107. <div class="btn btn-primary btn-fonts" ng-click="output=calc(op,operand1,operand2)">=</div>
  108.  
  109. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement