Given an array of objects (such as would represent a selection of items, for example), and an input, how do you go about binding the input value so that it represents a given property of all the objects?
The input should display state in the manner:
- if all values for this property are the same on all objects, display that value
- if at least one value is not the same, set the input.value to 'multiple'
- if all values are undefined, set the input.value to 'none'
I have the function that aggregates the values for a given property exposed on the scope:
// Return value (if all values are equal) or undefined (if not)
scope.getSelection('property')
I also have the function that sets a value on all the objects:
scope.setSelection('property', value)
I can't find a combination ng-value, ng-model and ng-change that allows me to both get from .getSelection() and set to .setSelection() automatically, so I'm assuming I have to write a new directive.
What's the idiomatic way to solve this problem?