2

Does using ng-model hold any advantage over using any other attribute on the element to achieve a two way binding within a directive?

For example if I had an isolate scope and decided I just want to load the items via the directive attribute itself.

scope: {
  items: "=myDirective"
}

<div my-directive="items"></div>

vs

<div my-directive ng-model="items"></div>
holographic-principle
  • 19,688
  • 10
  • 46
  • 62

1 Answers1

3

If the view in your directive can change the model (through inputs, selects, etc.), then you'll want to use ng-model so that you can you can use the ngModelController to update the model from the view. If you're always changing the model from controllers, then there's no need to use ng-model, as angular will update your view for you. The key is just if the view itself ever changes the model.

dnc253
  • 39,967
  • 41
  • 141
  • 157
  • I'll add that if you want to use ngModelController in your directive, don't use an isolate scope. See http://stackoverflow.com/questions/11896732/ngmodel-and-component-with-isolated-scope – Mark Rajcok Jun 19 '13 at 17:05
  • That's rather interesting, @MarkRajcok because I am using directives with isolate scopes. – holographic-principle Jun 19 '13 at 17:10