In this article, we shall see the building blocks in an Angular Application
Angular Application is modular in nature. Therefore, an Application is just a collection of the individual modules.
Modules are just blocks of code, which are created for a specific purpose.
Because of this, each module exports something like a value or a function or a class, which the other module can import and make use of.
In fact, an Angular framework itself is a collection of library modules.
Next building block is called a Component. We have already seen that we have a module, which has a block of code within them and this is nothing but a component.
For e.g. In metadata, we might have an HTML, which is going to be a view for our Component and our class contains a logic, which influences particular view. Let’s say that we have a Web page, where we have a navigation bar and main content. Now, we are going to create a component for each of these individual functionalities.
In our Angular Application, we will have at least one component called Root Component and all the other components are going to fall under this Root Component.
In this way, our Entire Application is broken down into easily manageable views.
Let’s say we have a sample piece of code given below. We are going to have Body tag, within the Body tag; we have root component and this component is nothing but a custom HTML tag.
It’s nothing but some sort of instruction, which allows us to modify DOM or extend its behaviour.
In simple words, Directives are nothing but some Metadata and Class.
- <p *ngif=”rathrola”>Prem</p>
If a component wants to get some data from a Server, then it might have a function to do so.
Another component wants to get the data, Component and the same function.
In order to avoid duplications, we make use of Servers.
A Service is nothing but a class, which gets the data or the configuration from the Server and after doing so, we will inject the Service to the two components. When we injected these two components, we make use of Services.
Any logic, which is not related to the view will be residing inside the Services.
Routers are responsible for the navigation. Thus, based on the URL, it will decide which view component will be presented to the user.
Thanks for reading the article. Happy Coding.
This is a guest post by Prem Kumar. If you would like to write for DotnetCrunch, check our guest posting guidelines.