On day six of the advent calendar I'm going to share some content from Chapter 3 of my book "Front-end Development with ASP.NET Core, Angular, and Bootstrap", which is all about Angular (v5). Specifically I'm going to introduce the concepts that make the foundation of Angular.
AngularJS vs Angular
I started writing this book in Summer 2015 with the hope of releasing it in Spring 2016 when the then ASP.NET 5 (and ASP.NET, MVC 6) were released. But unfortunately, as most people know, ASP.NET 5 Core had a long history full of fundamental changes that delayed the release of a complete working version, with both library and matching tooling till Summer 2017.
This had a lot of consequences also on chapter 3 about Angular: I started writing about AngularJS 1.5, but during the two years wait for ASP.NET Core to be done, the vNext of Angular went from Alpha, to Beta, to release of Angular 2, and later even to the releases of v4 and v5. So chapter 3 went through one complete rewrite and a few smaller ones.
The following is an extract of Chapter 3 about Angular, introducing the foundations of the framework.
Angular is a web application framework developed and maintained by Google and the open-source community. The framework has many features, like two-way data-binding, templating, routing, components, dependency injection, and so on. Unfortunately, like all frameworks of its breed, it has a pretty steep learning curve due to the many concepts you have to grasp in order to be fluent in it. Here is a list of the most important Angular concepts:
- Modules: Containers that group together blocks of functionalities that belong together, like components, directives, services, and so on.
- Components: Define the behavior of a “portion” of the screen.
- Templates: HTML files that define how the view for a component is rendered.
- Data binding: The process that connects a component to its template and allows data and events to flow between them.
- Directives: Custom attributes that enhance HTML syntax and are used to attach behaviors to specific elements on the page.
- Services: Reusable functionalities that are independent from the views.
- Dependency injection: A way to supply dependencies (services most of the time) to classes (other services or components).
- Metadata: Instructs Angular on how to process a class, whether it’s a component, a module, a directive, which services have to be injected, and so on.
Those terms might sound abstract at the moment, but the upcoming pages will make everything more clear, as all of these concepts are used to build a sample single-page application.
The development of the sample SPA is covered in the third chapter of my upcoming book Front-end Development with ASP.NET Core, Angular, and Bootstrap.