2016-09-30 14 views
0

から値を取得します。は、角度は、これは角JSで私のアプリで前の入力

http://cmpe-273-010825867-fall-2016.herokuapp.com/

問題であり、数字ボタンをクリックして、2つのテキストへのI入力値は、それらが入力されたとき。私がリセットすると、値は消えます。 しかし数値ボタンを使って値を再入力すると、値はリセット前の値に追加されます。なぜ

<div ng-app="myApp"> 

       <div ng-controller="myController" ng-init='isFocused=true'> 

<form> 

            <div class="col-lg-5 col-md-8 col-sm-12 col-xs-12"> 
             <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> 
            </div> 


            <div class="col-lg-2 col-md-8 col-sm-12 col-xs-12 text-center" style="font-size:32px"> 
             {{op}} 
            </div> 


            <div class="col-lg-5 col-md-8 col-sm-12 col-xs-12"> 
             <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}}"> 
            </div> 

            <script src="js/custom.js"></script> 

           </div> 

          </div> 


          <div class="col-lg-5"> 

           <div class="row"> 

             <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 eqProps text-center"> 
              = 
             </div> 


             <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"style="font-size:32px"> 

              {{output}} 

             </div> 

           </div> 

          </div> 

        </div> 



        <div class="row"> 


         <div class="col-lg-1"></div> 

         <div class="col-lg-7"> 

          <div class="row"> 

            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1"></div> 
              <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10"> 
               <div class="row-fluid"> 

                <button class="btn btn-danger btn-fonts" type="reset" value="reset" ng-click=" opReset=resetFields() ">C</button> 
                <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> 
                <div class="btn btn-default btn-fonts" ng-click="output=calc(op,operand1,operand2)" style="visibility:hidden">=</div> 
                <div class="btn btn-primary btn-fonts" ng-click="output=calc(op,operand1,operand2)">=</div> 

        </form> 

答えて

-1

NG-モデル値のために空の値(オペランド2、オペランド1)を作成してください

+0

http://jsfiddle.net/nzPJD/ –

1

var myApp = angular.module('myApp', []); 

myApp.controller('myController', function($scope) { 


    function resetFields(){ 
     $scope.opReset=' '; 
    } 

     function add(x, y) { 
     return x + y; 
     } 

     function sub(x, y) { 
     return x - y; 
     } 

     function mul(x, y) { 
     return x * y; 
     } 

     function div(x, y) { 
     return x/y; 
     } 

     function calc(op, x, y) { 
     return $scope.operators[op](parseInt(x, 10), parseInt(y)); 
     } 

     $scope.operators = { 
     '+': add, 
     '-': sub, 
     '*': mul, 
     '/': div 
     }; 
     $scope.op = '+'; 
     $scope.calc = calc; 

}); 

マイHTML:ここ

は私の角度コードでありますvalue = "operand1"を使用していますか?

<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> 

あなたは直接の値を初期化するために、NG-モデルを使用するだけでなく、Cボタンをクリックする上で、それをクリアすることができます。

テキストエリアコードを変更してvaluesを削除してください。

<input width="100%" type="text" class="form-control" id="operand1" style="height:50px; font-size:32px" ng-model="operand1" ng-focus=' isFocused="operand1" ' autofocus> 

そしてresetFields機能では、使用して値を変更します。

$scope.operand1=''; 
$scope.operand2=''; 
関連する問題