Reputation: 13
Is it a good practice to call services directly from a Angular JS Directive?
Here is an example: directive to take name as input and calls a service(connects to db) to get the HTML content and render it.
a service call is made inside the linkFn to get the HTML content
or
return { restrict:'EA', scope:{ name:"=", getPartial : "&" }, link:linkFn }
here getHTMLContent is implemented in the controller and calls the same service.
Upvotes: 0
Views: 85
Reputation: 30995
No. Imagine if you put that directive in an "ng-repeat". You'd have way too many calls to the server. How you retrieve your model should be separate from the way you present the model.
Upvotes: 1