JavaScript How can I conditionally set the value of an input using angular? conditional value input,ng-class conditional input value,html input

I am using the following angular binding on an input:

<li data-ng-repeat="value in model.Values">
  <input type="number"
       data-required
       data-min="-10"
       data-max="10"
       data-ng-model="value.Percentage"
       ng-disabled="model.IsDisabled" />

In the case that the model.IsDisabled is true, I need to disabled the input and set the value of the input to 0, if it changes to false I need to change it back to the original value.Percentage value.

This is as far as I have got as I am new to Angular, originally I had it as a directive but seemed overkill, can I achieve this with the standard bindings?

Answer:1

What you can possibly do is create another array in your controller like:

$scope.newValues = []
model.Values.forEach(function(index, value){
    if($scope.model.IsDisabled)
        $scope.newValues.push(0)
    else
        $scope.newValues.push(value)
})

and now use new array for binding in HTML.

If you do not want to create a new array, you can add new property to models like calculatesPercentage and use that for binding.

And you can keep a watch on model.IsDisabled to recalculate the array whenever it changes.

Answer:2

WhY this notation does not work const result1 = _model['dataarray[0]']; _model.dataarray exists and it is an array with 2 elements this "console.log(_model.dataarray[0])" works fines

WhY this notation does not work const result1 = _model['dataarray[0]']; _model.dataarray exists and it is an array with 2 elements this "console.log(_model.dataarray[0])" works fines

  1. data binding with livedata android
  2. data binding with fragments android
  3. data binding with textbox in c#
  4. data binding with recyclerview
  5. data binding with include layout
  6. data binding with viewmodel android
  7. data binding with mvvm android
  8. data binding with kotlin
  9. data binding with tabular data control
  10. data binding with recyclerview kotlin
  11. data binding with ngmodel
  12. data binding with web
  13. data binding with viewmodel
  14. data binding with androidx
  15. data binding with mvvm
  16. data binding with live data
  17. data binding with fragments
  18. data binding with windows forms
  19. data binding with jquery
  20. data binding with edittext android

I'd like to combine a set of $.each statements looping through an array of arrays containing objects of k:v pairs into a single $.each which I can increment. Structure of array returned from PHP: an ...

I'd like to combine a set of $.each statements looping through an array of arrays containing objects of k:v pairs into a single $.each which I can increment. Structure of array returned from PHP: an ...

  1. increment array foreach

Suceeded in randomizing a quote but now the values name and quote don't match, is there a way to make json.name and json.quote share the same random value? so Einstein's quote isn't matched with the ...

Suceeded in randomizing a quote but now the values name and quote don't match, is there a way to make json.name and json.quote share the same random value? so Einstein's quote isn't matched with the ...

Something peculiar is happening for me with jquery-ui. I'm importing several pieces of jquery-ui separately in my HTML: <script type="text/javascript" src="../third-party/jquery-1.10.2/jquery.min....

Something peculiar is happening for me with jquery-ui. I'm importing several pieces of jquery-ui separately in my HTML: <script type="text/javascript" src="../third-party/jquery-1.10.2/jquery.min....