0

i'm having 2 select fields and number of input fields as scope object properties

  $scope.resetAll=function(){
	    	$scope.tableVal=0;
	    };
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<select ng-model="tableVal.portfolio" ng-change="getProjectPhase(tableVal.portfolio)" class="form-control portfolioSelect" id="sel1" style="margin-top: -3px;">
     <option>blah blah<option>
     
      <select ng-model="tableVal.project" ng-options="v as v for (k,v) in selectOptions" class="form-control projectPhaseSelect" id="sel3" style="margin-top: -3px;">
         <option>blah blah<option>
        </select>
  
   <td>$<input  id="testingInput" type="number"step="0.02" ng-disabled="!tableVal.project" ng-model="tableVal.Prevention"> </td>
  
  
   <td>$<input  id="testingInput" type="number" step="0.02" ng-disabled="!tableVal.project" ng-model="tableVal.Appraisal"> </td>
  
  
   <td>$<input  id="testingInput" type="number" step="0.02" ng-disabled="!tableVal.project" ng-model="tableVal.InternalFailure"> </td>
  
  <button type="button" class="btn btn-primary" ng-click="resetAll()"style="margin-top: -11px;">RESET</button>
  
                                            

when i click reset button the $scope.tableVal=0; resets all the field, but in my case i want select values not to be replaced, i somehow managed to get the values and set it manually, but no use

function(portfolio,project){
	        	
	        	 $scope.tableVal=0;
	        	$scope.tableVal.portfolio=portfolio;
                $scope.tableVal.project=project;
}

how to resolve this

1 Answer 1

1

In resetAll method, reset all the values except those which are bind to the select.

for (var key in $scope.tableVal) {
    if (key !== 'project' && key !== 'portfolio') {
        $scope.tableVal[key] = 0;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

never thought about this.. greatttt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.