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?
Take the 2-minute tour
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
|