8

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 :)

Alex Osborn
  • 9,831
  • 3
  • 33
  • 44
apohl
  • 1,913
  • 27
  • 30

1 Answers1

5

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.

Community
  • 1
  • 1
Josh David Miller
  • 120,525
  • 16
  • 127
  • 95