Reputation: 19738
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>
Upvotes: 2
Views: 687
Reputation: 40337
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.
Upvotes: 3