The key to an evolving app is to create reusable services to manage all the data calls to your backend.
In this section we will not discuss any backend implementation in particular because there are so many options and flavours when it comes to backend implementations that it turns impossible to provide examples for every option.
We will focus instead on the app’s side of the problem, how to handle data calls, as this works the same and is independent on the way you implement the backend. We will talk about models and services and how they work together to achieve this.
Domain models are important for defining and enforcing business logic in applications and are especially relevant as apps become larger and more people work on them.
At the same time, it is important that we keep our applications DRY (don't repeat yourself) and maintainable by moving logic out of components themselves and into separate classes (models) that can be called upon. A modular approach such as this makes our app's business logic reusable.
This template is implemented using the latest version of Angular and it borrows it’s best parts. Angular enables you to create multiple reusable data services and inject them in components that need them.
Refactoring data access to a separate service keeps the component lean and focused on supporting the view. It also makes it easier to unit test the component with a mock service.
We encourage the usage of models in combination with services for handling data all the way from the backend to the presentation flow.
Because this is a template, and not a final app for production, we use static data that we store in local json files located in the assets folder.
Using these json files we simulate a real database that we query through the services.
For a production app you should use a real database.
So, once you have your real database you just need to change the way you get the data. Instead of doing a http get to the local json file you will do it to your DB.