Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I am writing an angularjs app with a simple CRUD service at the back-end. Every page contains a form and many elements are common between multiple forms. Some of these elements (dropdowns) trigger calls to backend service to populate other fields. This is causing repetitive code in the partials as well as in controllers and in unit-tests. As an e.g., there are forms of creating, updating and searching for employees. Each of these forms has a drop-down for department. When a department is selected, the backend service is called to fetch a list of sub-departments. While there is only one service to fetch the data, the code for calling the service and the UI elements are duplicated. Same with unit-tests for each controller. Is there a way to avoid this duplication? Can directives be used here to encapsulate the UI and controller logic and avoid repetition?

share|improve this question
    
Can directives be used ...of course they can. I like to use the same form and controller for edit/create for same entity and is simple to toggle and crudMode variable to do it –  charlietfl Jul 24 at 22:49

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.