I made two directives to setup custom error messages in AngularJS:
errors -> displays the error messages for a form
error-message -> sets up a custom error message on an input
For some reason whenever I add the error-message
directive to the element the ng-model binding no longer works (but validation does).
See here http://jsfiddle.net/apohl/A8Vgk/111/
Help please :)
The problem is that your errorMessage
directive uses an isolate scope. Isolate scopes affect the entire element, so the ngModel
directive was being evaluated in an isolate scope - which obviously can't work - the model is on the parent scope.
I'm not sure why you established an isolate scope here. Since you are trying to create a component that must interact with other directives, an isolate scope is not the best choice. Since errorMessage
doesn't affect the current scope, you may not need any defined scope, but you could use a child scope if you so chose.
Take a look here to read more about when to use each type of scope on a directive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With