Today in this tutorial we will discuss about creating components, models and services in angular. I highly recommend to watch previous two parts of this tutorial before procedding to this if you have not watch the previous parts of this series. First of all let us have a general introduction about these topic and what they are used for. First of all let's take about components. So, what are components? well, components are like the building block of angular App. for example in a typical angular app there are lots of components, header could be one of component, navigation could be another component, footer could be another component, similarly a user form can be one of the components and so on. moreover the components are reusable i.e it can be used anywhere in the app. Now, lets talk about models, models represents the logical structure of data. i.e a model is used as a carrier of data between the user interface and the service. whereas, service is a class that is generally used to make connection with the server or any other logic.
Now, moving on let us now start by creating components. For this operation open new terminal window, and then in the terminal window enter the following command to create a component and then press enter.
ng g c components/user
After you run the above command components is created and app.module file is updated. which is confirmed in the figure below:
Similarly let us now create a service using the command line below and then the service gets created :
ng g s service/user
Now, at last let us create a model using the command line below:
ng g cl models/user --type=model
Here on creating model and service 2 files are created on each process. and finally our solution explorer will looks like below:
In this way we created components, models and service in this tutorial. In next tutorial we will learn about communicating between these components. so, please stay tuned.