Senthil kumar
Senthil kumar

Reputation: 13

Directives calling services directly

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

Answers (1)

adam0101
adam0101

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

Related Questions