I'm trying to figure out a way to use ngModel and NgModelController to create a directive that modifies the model value on the "first pass" -- that is -- whatever the user passed into it gets modified automatically and doesn't wait for user input, yet still retaining the "pristine" nature of the model.
For instance -- let's say I want a directive that takes whatever the user types and converts it to lowercase (contrived example but it's simple enough to demonstrate the issue): http://plnkr.co/edit/jnE3s8MRr1tFCX0WVYel?p=preview You'll notice here that the initial model value stays UPPER_CASE until I type into it -- what I would like is for the parsing to happen on the initial model and return it back as "lower_case" without the user having to type. So a few supporting questions: 1) Can I do this without calling $setViewValue() from inside of my $formatters method? If not, is this considered "ok"? 2) If I do call $setViewValue (either directly in $formatters or by removing the newValue === oldValue in my $watch) -- then the control will be set to $dirty even though the user did not interact with it. Any way to avoid that? 3) Am I approaching this all wrong? Would there be a completely different way to write such a component? Note -- the original impetus for this question was more involved -- I have a directive that can take a Date, a Moment object, or a formatted date string in the ng-model and display it in a datepicker, but it always spits back out a Moment object -- that's why I want the initial model to change on the first pass. Thanks, Paul -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
