opened
johnlindquist
username_0
Hi Deborah!

I thought the `valueChanges` approach for validation was a little unwieldy so I thought I'd update the part I saw on a slide of your ngconf presentation to using a more declarative approach with template validation and .ng-invalid.

Cheers,
John
An example of moving validation into the templates and using .ng-inva…
issue
created
DeborahK
username_1
Hey John! Thanks for your suggestion.
Did you see in the slides/talk that I covered *3* approaches?
1) Template driven ... with the code in the template (similar to what you did here). The code for that is in the movie-edit-template.component.* files.
2) Partial model-driven ... with the code partially in the template and partially in the component class. The code for that is in the movie-edit-model.component.* files.
3) Fully model-driven ... with the code *primarily* in the component class. That allows for unit testing of the code and for more advanced logic scenarios (such as retrieving the messages from a file/table or adjusting the validation/messages based on the user, etc).
Or is there something different that you have done here than what I provided in movie-edit-template.component.*?
Thanks again!
comment
created
johnlindquist
username_0
I do understand the differences between the approaches so I was mostly speeding through the recording of your video, but let me backup a bit:

What caught my eye was how you were using `valueChanges` in the "fully-model driven" approach. Instead of moving everything into the template, I should have shown what I would have done with combining streams in Rx to achieve what was written the `subscribe` block. I believe if you're going to use streams (such as `valueChanges`) that messages/errors/etc should all be separate streams that you would subscribe to and create off of the `valueChanges` stream. I'll create a separate pull request to explain what I mean.

I did jump the gun without seeing that you already implemented template approach, but I did add your `range` validator to a custom validator directive just for fun. :)
comment