AngularJs: set conditional minimum and maximum value for checking in the number input field

I created a web page containing a form with two input fields for number field1and field2. I am doing a check in these fields. field1has a value of min1 and a maxvalue of 100000, but it field2should have a value of min max field1or 1, which is more, but maxequal to 100000. I tried to assign ng-model field1as min field2, but it does not work.

<div class="row">
  <div>
    <input ng-model="priceminrange" name="priceminrange" type="number"
    class="form-control" value="" placeholder="MinRange" min="1" max="100000">
    <span ng-show="form.priceminrange.$error.number">The value is not a valid number</span> 
    <span ng-show="form.priceminrange.$error.min || form.priceminrange.$error.max">
    The value must be in range 1 to 100000</span>
  </div>
  <div>
    <input ng-model="pricemaxrange" name="pricemaxrange" type="number"
    class="form-control" value="" placeholder="MaxRange" min={{priceminrange}} max="100000">
    <span ng-show="form.pricemaxrange.$error.number">The value is not a valid number</span> 
    <span ng-show="form.pricemaxrange.$error.min || form.pricemaxrange.$error.max">
    The value must be in range {{priceminrange}} to 100000</span>
    form.pricemaxrange.$error = {{form.pricemaxrange.$error}}
  </div>
</div>
+4
source share
2 answers

try it

On the controller, create a scope.

$scope.priceminrange = 1;
+2
source

. priceminrange - Angular, , . , , $modelValue, , , ( ).

- , , "".

<input ng-model="pricemaxrange" type="number" min="{{form.priceminrange.$modelValue}}">
+7

All Articles