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...

Getting started with iOS programming using Swift (Part 1)

I have not been too fond of Objective-C, which was the primary reason for me to stay away from making iOS apps till now. So what changed? Well Apple has done something very interesting recently and that is the introduction of a new programming language i.e. Swift. Swift is awesome, it almost feels like Python, C++ and Objective-C had a baby with some of their good parts in them. So I have been getting to know Swift and it is an awesome language to program in. What I am going to share with this and a series of blog posts are solutions to some problems that i have encounter while i am trying to finish my first iOS app. The one hurdle that I have encountered while getting started on developing an iOS app is that a majority of the solutions for iOS specific problems provide solutions to them using Objective-C. Which is fair, because Swift has not been around for that long. Anyway let us get started with a few basics, A few basics I would highly recommend having a read of this book...