I'm new to AngularJS, so forgive me if this is a noob question. The documentation is pretty terse, so I may have missed something obvious!
I'm considering migrating a bunch of custom in-house code to Angular, and I have to make Angular work with our REST pattern, in which an input looks like this:
foo: {
value: 100,
min: 50,
max: 150
}
Value becomes the value displayed in an input
element, and min and max are (currently) bound to min and max attributes. These are later picked up by a validation function. If value is outside of the min-max range, it is adjusted back into that range.
Anyway, I'm trying to do something like:
<input type="text" ng-model="foo" my-bind />
... and override ngModel
with a directive named myBind
to manage the relationship, so that the value is read and written to foo.value
.
I would then use a custom validator later to handle the min/max attributes.
Can anyone provide an example of how I might achieve such a binding? I've not had much luck making it work so far.
... or maybe my whole approach is stupid? I do have to work with the data structure above though, I can't change that in the near future.