AngularJS validation that is dependent on other scope property values -


I am trying to apply some assumptions using AngularJS. My area has a list of inputs related to the list of objects, and I want to make sure that the value in each input is before or equal to the input (assuming I only enter numerical values, inputs)

This means that when a value changes, it needs to be checked:

  • The new value is still equal to or equal to the previous item (if < / Li>
  • The best way to go about this is not sure, but I would like to use the AngularJS verification framework as much as possible. I get 3 possible solutions:

    1: Create a custom directive to verify

    I have found examples that do this, but I have 2 questions here:

      < Li> Realm of Reality / Properties that you currently Accept How will the use of relative properties?
    • If the input value is tied on index 1, for example, changed, whether to evaluate the input value based on the index 2 It is possible to trigger the instruction, because changing the value on index 1 can invalidate it? So far, I have noticed that a directive function has only started for binding which has just changed.

    2: Use the UI-validation

    In this case I will be able to supply the index of the list item in the verification item. Therefore, it meant that I can use the value of the previous list item for evaluation. But I still had a problem that was removed just for the item that has changed - the next item in the list was not re-evaluated.

    3: Apply an on-change event handler to each bound input value

    But in this case, I do not know To call that $ setValidity function, if all I have got a handle on an 'underlying scope' property. The code below fails:

      if (eval ($ scope.items [i] .value) eval ($ scope.items [i - 1] .value) ) {$ Scope item [i]. $ SetValidity ('notinorder', incorrect); }  

    I think I can apply this by using another method, to touch without any AngularJS verification framework - but if it is used in 'right' way , Then I would like to know ...

you line Need to pass the variable verification function and set the verification for it. Here's an example:


Comments