Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am currently implementing an AngularJS directive. It is fundamentally a reusable widget comprised of a select box and a table which populates based on the item in the select box.

My point of contention is whether or not I should inject a data dependency into the directive so that the directive can initalize itself from our database, or whether I should expose the select box option model and allow the user to populate it from the controller.

The select box options will always be the same, at least they are always single sourced from the same endpoint. That being the case I am tempted to wrap up the data retrieval internally in my directive to avoid requiring every user of this widget inject our service dependency into their controller in order to retrieve that same data.

If I do this, then I seem to be violating the 'seperation of concerns' but alternately if I don't bake the initialization in am I not violating DRY?

One Blog I read that tangentially approached this made the point that what we are actually writing with our declarative HTML (in an ANgularJS app) is a DSL, and in that context it is permissible mix these concerns.

So, what should be my approach to my data dependency in the above scenario so that I not only follow best practices but also, create a directive which is optimal given my DOMs 'DSL'.

share|improve this question
1  
There are no hard and fast rules here. Practices like DRY and SOC are just that: practices. Which approach best meets your software's functional and non-functional requirements? –  Robert Harvey Oct 23 '14 at 20:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.