Skip to main content

Getting Started with Angular 18 (2025): A Complete Beginner’s Guide to Directives, Two-Way Data Binding, and How It Compares with React and Vue

Introduction

If you’re stepping into modern front-end development in 2025, you’ve probably heard of Angular, React, and Vue — the three giants powering the web today. Angular, built and maintained by Google, remains a top choice for scalable enterprise applications and robust single-page apps (SPAs).

This tutorial is your step-by-step beginner’s guide to getting started with the latest version — Angular 18 (as of 2025). We’ll cover how to set up your first project, create custom directives, understand two-way data binding, and compare Angular with ReactJS and VueJS.


🧭 What Is Angular?

Angular is a TypeScript-based front-end framework designed for building dynamic, modular, and reactive web applications. Unlike React (a library) or Vue (a progressive framework), Angular provides a complete solution — including routing, forms, HTTP communication, and dependency injection — right out of the box.

Some standout Angular features include:

  • 🧩 Modular architecture using components and modules

  • 🔁 Two-way data binding

  • Dependency Injection

  • 📦 Built-in tools for routing and HTTP

  • 🧠 Strong TypeScript and Reactive Programming support


⚙️ Setting Up Angular 18

1. Install Node.js and Angular CLI

Before anything else, make sure you have Node.js (v18 or later) installed.
You can check your version by running:

node -v npm -v

Then, install the Angular CLI globally:

npm install -g @angular/cli

Verify the installation:

ng version

2. Create a New Angular Project

Now, create a new project:

ng new my-angular-app

During setup, you’ll be asked a few questions (like adding routing and choosing CSS/SCSS). Once done, navigate to your new folder:

cd my-angular-app

Start the development server:

ng serve

Then visit http://localhost:4200 in your browser — you should see the default Angular welcome page 🎉


🧱 Understanding Angular Directives

Directives are one of Angular’s most powerful features. They let you extend HTML’s capabilities by adding new behaviors to elements in the DOM.

Angular comes with three types of directives:

  1. Component Directives — These are directives with templates (basically components).

  2. Structural Directives — Modify the DOM structure (like *ngIf, *ngFor).

  3. Attribute Directives — Change the appearance or behavior of an existing element (like ngStyle, ngClass).


Creating a Custom Directive (Step-by-Step)

Let’s build a simple custom directive that highlights text when the user hovers over it.

  1. Generate the directive using Angular CLI:

    ng generate directive highlight
  2. Open highlight.directive.ts. It should look like this:

    import { Directive, ElementRef, HostListener, Input } from '@angular/core'; @Directive({ selector: '[appHighlight]' }) export class HighlightDirective { @Input() appHighlight = ''; constructor(private el: ElementRef) {} @HostListener('mouseenter') onMouseEnter() { this.highlight(this.appHighlight || 'yellow'); } @HostListener('mouseleave') onMouseLeave() { this.highlight(''); } private highlight(color: string) { this.el.nativeElement.style.backgroundColor = color; } }
  3. Use it in a component template:

    <p appHighlight="lightblue">Hover over me to see the highlight effect!</p>

You’ve just created your first custom directive — one of the building blocks of Angular development!


🔁 Two-Way Data Binding in Angular

Angular’s two-way data binding keeps your component class and template in sync automatically. When a user updates input fields, the component’s data updates instantly — and vice versa.

You use Angular’s special syntax called [(ngModel)] (known as the banana-in-a-box syntax 🍌📦).

Example:

In your component file (app.component.ts):

export class AppComponent { username: string = 'Bhuman'; }

In your template (app.component.html):

<input [(ngModel)]="username" placeholder="Enter your name"> <p>Hello, {{ username }}!</p>

Note: For ngModel to work, you need to import FormsModule in your app.module.ts:

import { FormsModule } from '@angular/forms'; @NgModule({ imports: [BrowserModule, FormsModule], ... }) export class AppModule {}

Now, as you type in the input field, the text in the paragraph updates in real-time — that’s two-way binding in action!


⚖️ Angular vs React vs Vue (2025 Comparison)

FeatureAngular 18React 19Vue 4
TypeFull-fledged FrameworkUI LibraryProgressive Framework
LanguageTypeScriptJavaScript / TypeScriptJavaScript / TypeScript
Learning CurveSteep (more concepts)ModerateEasy
Data BindingTwo-way bindingOne-way (with manual handlers)Two-way (v-model)
DOM HandlingReal DOMVirtual DOMVirtual DOM
State ManagementBuilt-in via servicesRedux / Context APIVuex / Pinia
PerformanceExcellent for large-scale appsVery fast for UI-heavy appsFast and lightweight
Use CaseEnterprise appsDynamic UIsSmall to mid-scale apps

In short:

  • Use Angular if you want a full solution with strong TypeScript integration.

  • Use React for flexible, component-based UI development.

  • Use Vue if you want simplicity with good scalability.


🧠 Final Thoughts

Angular remains one of the most complete and enterprise-ready frameworks in 2025. Its directives, dependency injection, and two-way data binding make it a developer favorite for building large, maintainable apps.

If you’re just starting out:

  • Learn components, directives, and data binding.

  • Practice using the Angular CLI.

  • Gradually explore services, routing, and RxJS for reactive programming.


Recommended Next Steps

Comments

Popular posts from this blog

Upload to AWS S3 from Java API

In this post, you will see code samples for how to upload a file to AWS S3 bucket from a Java Spring Boot app. The code you will see here is from one of my open-source repositories on Github, called document-sharing. Problem Let’s say you are building a document sharing app where you allow your users to upload the file to a public cloud solution. Now, let’s say you are building the API for your app with Spring Boot and you are using AWS S3 as your public cloud solution. How would you do that? This blog post contains the code that can help you achieve that. Read more below,  Upload to AWS S3 bucket from Java Spring Boot app - My Day To-Do (mydaytodo.com)

Addressing app review rejections for auto-renewing subscription in-app purchase (iOS)

The ability to know what the weather is like while planning your day is a feature of  My Day To-Do  Pro and as of the last update it’s also a part of the  Lite version . Unlike the Pro version it’s an auto-renewing subscription based  in-app purchase (IAP)  in the Lite version. What means is that when a user purchases it, the user only pays for the subscription duration after which the user will be automatically charged for the next period. Adding an  auto-renewing  subscription based IAP proved to be somewhat challenging in terms of the app store review i.e. the app update was rejected by the App Review team thrice because of missing information about the IAP. Therefore in this post I will share my experiences and knowledge of adding auto-renewing IAP in hopes to save someone else the time that I had to spend on this problem. In-App purchase This year I started adding IAPs to My Day To-Do Lite which lead to learning about different types of IAP...

Serving HTML content in an iOS app that works in iOS 7 and later (using Swift)

As I have mentioned in an earlier post , I really enjoying coding in Swift. Now what am I doing with it? Well I am trying to build an HTML5 app that must work on devices with iOS 7. So in iOS8 apple has introduced a whole bunch of features that facilitate easy communication between web content and lets just call it back-end Swift code, but those features are not in iOS 7. So why do I want to build something that would work in an older OS? well I do not expect existing iOS users to upgrade to iOS 8 straight away and i also know a couple of people who would be very reluctant to upgrade their iPhones to iOS 8. Now in case you do not, you can have a read of the "Working with WebViews" section of this post , to know how to serve HTML content with WebViews. So when I started building my app, I wanted to know: How do I invoke some Swift code from my HTML content? Well the solution to this may feel a little bit "hacky" but it is a solution to achieve this.  The followi...