This is my first post under this group so if my question does meet a 
certain criteria, just let me know and I'll be happy to update accordingly. 
There is a diagram attached to make up for my confusing description...

My basic setup is that I have a view with a corresponding 
controller. Inside that view is a button. When the button is clicked, I 
need to...
1. Check the value of a date-picker within that view (I am storing the date 
inside a service so that other modules can have access to this value)
2. Depending on the date selected, call one of four angular services 
(actually, they're factories) to retrieve data from a back-end application. 
This is done from the service mentioned in item 1.
3. Use the data returned in item 2. to generate a PDF with some third-party 
library. The way the data is obtained in step 2. should not be coupled at 
all to the service/directive in question.

My question is whether I should be using a directive or a service for step 
number 3. I am aware of the basic differences between the two but this 
example does not seem to fall clearly into either camp.

As far as I can tell, the pros and cons of each option are...
Directive:
pro - I can list pdf metadata (which will be used in step 3.) as attributes 
of the button element in the markup
pro - I want other people to be able to easily use the directive/service 
and it seems easier to use as a directive?
con - There's no simple way to share data returned in 2. with the 
third-party library call in 3.

Service:
pro - Data returned in 2. can be easily injected/seen in 3.
pro - From what I hear, testing will be easier.
con - Services are singletons but I may want to have more than one 
'Generate PDF' button
con - The DOM may be slightly modified on page-load to change from a button 
to a flash object if the browser is IE and this is a big no-no in services.

<https://lh4.googleusercontent.com/-0G6olPmrTEU/U03fXC5y_zI/AAAAAAAALqw/YcttvYi8Dzs/s1600/photo.JPG>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to