Hubert
12 min
November 30, 2024

Introduction to Angular - basic definitions and concepts

Angular is a TypeScript-based front-end framework used to create interactive web applications. Thanks to its modular architecture and built-in features, it allows to build scalable web applications, including SPAs (Single Page Applications), dynamic interfaces, CRM systems, e-commerce platforms and social networks. It facilitates integration with the backend (HttpClient), supports progressive (PWA) and mobile applications thanks to the Ionic Framework. Ideal for small and large teams.

Read more
Introduction to Angular - basic definitions and concepts

What is Angular?

Angular is a frontend framework based on TypeScript, which enables the development of interactive web applications. With its modular architecture and rich base of built-in features, Angular is the tool of choice for both large corporations and small development teams.

What is Angular used for?

Angular is primarily used for:

  • Web application development: Angular allows you to design scalable web applications that can support millions of users. It is perfect for projects such as CRM systems, e-commerce platforms and social networks.
  • Create single-page applications (SPA): With Angular, you can create applications that work like desktop software – quickly and without reloading the page.
  • Backend integration: Angular facilitates API communication with built-in tools such as the HttpClient module, which speeds up data exchange between the application and the server.
  • Build dynamic UIs: Angular allows you to easily manage dynamic UI changes, adjusting the displayed data in real-time in response to user actions.
  • Create cross-platform applications: Angular supports building progressive web applications (PWAs) that can also run offline, and mobile applications thanks to integration with the Ionic Framework.

Key features of Angular:

  • Single Page Application Development (SPA): Angular allows you to build applications that load once and then dynamically update the content on the page without reloading.
  • Based on TypeScript: TypeScript, a language that oversees JavaScript, provides static typing and advanced features that improve code readability and reliability.
  • Performance support: Angular optimizes application performance with a sophisticated DOM change management system (e.g. using the Zones mechanism).
  • Ecosystem: The framework offers a rich set of tools and libraries, such as Angular CLI and RxJS, that make it easy to create, test and deploy applications.
Are you looking for trusted IT company?
Are you looking for trusted IT company?
Are you looking for trusted IT company?
Contact us!

What are the most important differences between AngularJS and Angular?

Moving on to modern Angular (versions 2.0 and above), it is worth first understanding how it differs from its predecessor, AngularJS. Although both versions bear a similar name, they differ significantly in approach, architecture and technology. Below is a description of the differences:

Technology:

  • AngularJS was based on pure JavaScript, which makes it more error-prone and harder to scale.
  • Angular as of version 2.0 uses TypeScript, which offers advanced typing and better code analysis tools.

Architecture:

  • AngularJS is based on the MVC (Model-View-Controller) model , where logic, views and data are separated.
  • Angular since version 2.0 has moved to a component-based approach , which enables better reusability and organization of code.

Performance:

  • AngularJS used bidirectional data binding in every case, which could lead to performance issues in larger applications.
  • Angular offers a more advanced change management system, based on the virtual DOM and the Zone.js mechanism.

Tools and ecosystem:

  • AngularJS had limited tooling support. An Angular CLI was created for Angular, which simplifies the process of creating, testing and deploying applications.
  • Angular makes extensive use of the RxJS library , which allows reactive programming.

How does Angular’s architecture work? What do the terms MVC and MVVM mean?

Angular is a framework with a modular, component-based architecture. Its basic idea is the separation of responsibilities, which allows to create applications that are easy to maintain, test and extend.

Key Angular architecture concepts:

  1. Components as a central element:
    • In Angular, components act as a view (UI) and a controller (logic).
    • Each component is a self-contained unit consisting of an HTML template, styles and logic written in TypeScript.
  2. Model MVC (Model View Controller):
    • Model: is responsible for storing application data and interacting with the backend.
    • View (View): presents data to the user in the form of an interface.
    • Controller: mediates between the model and the view, processing data and handling user events.
  3. MVVM (Model-View-ViewModel):
    • Angular uses a variation of MVC, referred to as MVVM, where the ViewModel is responsible for synchronizing data between the model and the view.
    • Communication between layers is done via data binding, which eliminates the need for manual state management.
  4. Data Flow Management:
    • Data flows unidirectional (unidirectional) in Angular in most cases, which improves performance and code readability.
    • Two-way data binding is used where necessary, such as in forms.

What is a module in Angular and why is it so important?

Modules are one of the pillars of Angular’s architecture. They allow you to organize your application into logical units, which makes it easier to manage its structure, reuse code and improve performance by allowing you to introduce mechanisms such as lazy loading.

Key aspects of modules in Angular:

Czym jest moduł?

  • A module in Angular is a class decorated using the @NgModule decorator .
  • It groups application elements, such as components, directives, services or pips, which are logically related to each other.
  • Angular uses modules to better manage dependencies and limit their scope.

The main module of the application – AppModule:

  • Every Angular application has a main module, usually called AppModule. It is from it that the initialization of the entire application begins.
  • AppModule captures key elements of the application and integrates external Angular modules such as BrowserModule or HttpClientModule.

Division into functional and shared modules:

  • Functional modules: They organize specific parts of the application, such as a user module(UserModule) or an administration module(AdminModule).
  • Shared Modules: Store components, directives or pips that are used in multiple places in the application, such as SharedModule.

Why are modules important?

  • Modularity: Make it easier to organize code in larger projects.
  • Lazy loading: thanks to modules, Angular loads only the parts of the application that are currently needed, which significantly improves page load time.
  • Isolation: modules allow you to limit the visibility of application elements – for example, components declared in one module are not automatically available in others.

Decorator @NgModule:

  • Key fields of the decorator:
    • declarations: List of components, directives and pip declared in the module.
    • imports: Modules that are required for components inside the module to function.
    • providers: Services available for items in the module.
    • bootstrap: The main component of an application (usually in an AppModule).

What is a component in Angular and what basic elements does it have?

Components are the basic units that build the user interface in Angular. Each component is responsible for one slice of the UI – it can be a button, a form, a table or even an entire view.

Key aspects of the components:

Angular component definition:

  • A component is a class in TypeScript marked with the @Component decorator .
  • It combines logic (in TypeScript) with template (HTML) and styles (CSS/SCSS) to form a self-contained functional unit.

Component structure:

  • Decorator @Component:
    • selector: A unique HTML tag used to embed a component in other views.
    • templateUrl or template: The path to the HTML file or direct HTML code used as the component view.
    • styleUrls or styles: Path to CSS/SCSS files or direct style code.
  • Component class: The logic of how a component works, written in TypeScript. Handles the data, events and functionality associated with a given UI component.

Communication between components:

  • Inputs (@Input): Allow data to be passed to the parent component.
  • Outputs (@Output): Emit events to the parent component, such as button clicks.

Component life cycle:

  • Angular offers built-in methods for component lifecycle management, such as ngOnInit, ngOnChanges , ngOnDestroy. With these, the developer can react to data changes, initialize settings or release resources.

Reusability of components:

  • Components can be used multiple times in different parts of the application.
  • Thanks to its modular approach, it can be easily moved and used in different projects.

Declaring components in a module:

  • Each component must be declared in the appropriate module(declarations in @NgModule) so that Angular knows to use it.

Component example:

import { Component } from '@angular/core';

@Component({
  selector: 'app-hello',
  template: `<h1>Hello, {{name}}!</h1>`,
  styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent {
  name: string = 'Angular';
}

How does the routing system work in Angular?

Angular’s routing system allows users to navigate between different views of the application, keeping it as a Single Page Application (SPA). This allows the user to move between pages, and the application dynamically updates views without reloading the entire page.

Key elements of routing:

  • RouterModule: An Angular module that manages routes in an application. It is imported into the main module or functional modules.
  • Routes: An array of objects that define paths and the components assigned to them.
  • Directives:
    • RouterLink: Creates navigation links.
    • RouterOutlet: Displays the content corresponding to the currently active route.
  • Lazy loading: The ability to load modules or views only when they are first used, improving application performance.

Configuration example:

const routes: Routes = [
  { path: 'home', component: HomeComponent },
  { path: 'about', component: AboutComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}

Routing in Angular is a powerful tool that simplifies view management and improves user experience in SPA applications.

What is two-way data binding?

Angular’s bidirectional data binding enables real-time data synchronization between the model and the view. This means that changes made by the user in the interface are automatically reflected in the application logic, and vice versa.

How does two-way data binding work?

  • In Angular, these are implemented using the [(ngModel)] directive .
  • Connects component data to form or interface elements, such as text fields.

Application:

  • Forms: Enables automatic updating of user input.
  • Interactive UI: Allows the interface to react instantly to changes in data.

Bidirectional data binding is an important functionality that significantly speeds up building dynamic applications in Angular.

How to start a project in Angular?

Getting started with Angular requires several steps related to preparing the environment and a basic understanding of how the framework works.

1. Preparing the environment

To work with Angular, you need to:

  • Install Node.js, which allows you to manage dependencies and run Angular projects.
  • Set up Angular CLI, an Angular project management tool that makes it easy to create, build and test applications.
  • Choose a code editor, such as Visual Studio Code, which can support working with Angular and TypeScript thanks to plug-ins.

2. Creating a new project

Angular CLI allows you to quickly create a ready-made application framework. Once the project is created, the file and directory structure is generated automatically, allowing you to start developing the application right away. The application by default contains basic elements such as modules, components and configuration.

3 Launching the application

The created Angular project can be launched locally using a development server. Once launched, the application runs in the browser at a local address, allowing for immediate testing and iteration.

4. Understand the structure of the project

Angular organizes applications into modules, components and services:

  • Modules group related functionalities.
  • Components are responsible for building the user interface.
  • Services store business logic and allow data sharing between components.

5. Adding functionality

The Angular CLI makes it easy to create new components, services or modules, allowing you to gradually expand your application. At this stage, you can start implementing logic, creating views and connecting to the backend using Angular’s built-in tools, such as HttpClient.

6. Building and implementing

The finished application can be built in a production version that is optimized for performance and size. The built application can be deployed to a web server or cloud platform.

Advantages of Angular:

  1. Modularity and Scalability:
    • With its modular architecture, Angular makes it easy to organize large projects and supports their development over time.
  2. TypeScript support:
    • Angular is based on TypeScript, which allows for error detection at the code writing stage, better typing and more readable code.
  3. Two-Way Data Binding:
    • It enables real-time synchronization of data between the view and the model, which simplifies the creation of dynamic user interfaces.
  4. A rich ecosystem:
    • Angular CLI, RxJS, built-in routing and other tools support developers at every stage of their work.
  5. Google support:
    • Regular updates and long-term support (LTS) ensure the stability of the framework.
  6. Reactive Programming:
    • With RxJS, Angular offers advanced support for asynchronicity, which is crucial for high-performance applications.
  7. Lazy Loading and Performance Optimization:
    • Modules can be loaded only when they are needed, reducing application loading time.

Disadvantages of Angular

  1. Learning curve:
    • Angular is extensive and requires knowledge of TypeScript, RxJS, as well as component and Dependency Injection principles, which can be a challenge for beginners.
  2. Large initial size:
    • Angular applications have a larger initial size compared to lighter frameworks such as Vue or Svelte.
  3. Complicated configuration:
    • Although the Angular CLI simplifies project development, more advanced configurations can require significant technical knowledge.
  4. Performance in small-scale applications:
    • For smaller projects, Angular can be too “heavy” and introduce unnecessary complications.
  5. Frequent version changes:
    • While Google’s support is an advantage, frequent updates to the framework can require regular code changes, which can be cumbersome.

FAQ – Frequently Asked Questions:

1 What is Angular used for?
Angular is used to create dynamic, scalable web applications, especially SPA (Single Page Application) type. It allows building interactive and responsive user interfaces with advanced data management features and application logic.

2 What is the difference between Angular and React?
Angular is a full framework that offers a complete solution for building web applications, while React is a library focused on creating UI components. Angular is based on TypeScript, has built-in tools such as routing, and a structured module system. React requires the use of additional libraries for full functionality.

3 Is Angular Java or JavaScript?
Angular is based on TypeScript, which is an overlay of JavaScript. It has no relation to Java, despite the similarity in name. Angular applications run in the browser using JavaScript.

4 Is Angular used on the frontend or backend?
Angular is a frontend framework, used to build user interfaces. However, it can work with any backend, such as those written in Node.js, Java, PHP or Python.

5. can you use JavaScript in Angular?
Yes, Angular supports JavaScript, but by default it uses TypeScript, which extends the capabilities of JavaScript by adding typing and more advanced features.

6 Why do Java developers often choose Angular?
Angular is popular among Java developers because it has a structured approach, clear modularity principles and tools that resemble backend solutions (e.g. Dependency Injection). It is easier to understand for people who are used to writing applications in a structured way.

Connected articles
Introduction to Angular - basic definitions and concepts
7 min
January 9, 2025
What are HTML semantic tags and why should you use them?
HTML, or HyperText Markup Language, is the basic language that builds the structure of websites....
Learn more
Introduction to Angular - basic definitions and concepts
8 min
December 29, 2024
Next.js - first steps and installation
Next.js is a modern React-based framework that makes it easy to create high-performance web applications....
Learn more
Introduction to Angular - basic definitions and concepts
8 min
November 5, 2024
State management in React: Redux, Context API and Recoil
State management is a key aspect of building React applications. In this article, we will...
Learn more
See all
Discover more topics