Home/Blog/Programming/AngularJS tutorial for beginners
Home/Blog/Programming/AngularJS tutorial for beginners

AngularJS tutorial for beginners

8 min read
Jan 20, 2025
content
What is AngularJS?
AngularJS vs. Angular
Why should I choose AngularJS?
Key concepts of AngularJS
How can I set up AngularJS?
How to set up AngularJS using a CDN
How to install AngularJS locally
How to create a “Hello World” app in AngularJS
Step 1: Create an HTML file
Step 2: Include the AngularJS library via CDN
Step 3: Create the JavaScript file
Step 4: Include the AngularJS module and controller
Project structure
Demo
Next steps
Conclusion

Become a Software Engineer in Months, Not Years

From your first line of code, to your first day on the job — Educative has you covered. Join 2M+ developers learning in-demand programming skills.

Key takeaways:

  • AngularJS is an open-source JavaScript framework developed by Google for building single-page web applications.

  • AngularJS uses two-way data binding and an MVC (model-view-controller) architecture.

  • Key concepts in AngularJS include modules, controllers, directives, services, and data binding.

  • AngularJS can be set up using a CDN or by downloading it locally.

  • While AngularJS is simpler to learn, modern Angular (The TypeScript-based version of Angular) is recommended for new projects due to improved features and performance.

AngularJS has played a major role in shaping modern web development frameworks, setting the foundation for building dynamic and robust single-page applications (SPAs). Known for its two-way data binding, dependency injection, and ease of integration with other libraries, AngularJS remains a valuable framework for developers looking to understand the evolution of web technologies.

Whether you’re a complete beginner or have some coding experience, we’ll walk you through everything you need to know about AngularJS to get started. By the end of this guide, you’ll have created a working “Hello World” app in AngularJS and gained a foundational understanding of its core concepts.

This blog serves as a beginner guide to AngularJS. If you are looking for a tutorial on Angular and not AngularJS, navigate to this blog: Angular for Beginners: A Step-by-Step Guide.

What is AngularJS?#

AngularJS is an open-source web application framework developed in 2009 by Misko Hevery and Adam Abrons. While Google maintained it until January 1, 2022, the framework no longer receives updates or official support. AngularJS simplifies the development and testing of single-page web applications by providing a framework that organizes JavaScript, HTML, and CSS code.

With its powerful directives and modular structure, AngularJS simplifies the development process and encourages the writing clean, maintainable code. This is invaluable when trying to break into the world of coding and land your first job in web development.

AngularJS vs. Angular#

AngularJS is the older, JavaScript-based version of the framework. It uses a more traditional approach to web development, focusing on two-way data binding and directives using MVC architecture. It is primarily used to maintain legacy applications. A timeline of its versions is provided below:

Timeline of AngularJS versions
Timeline of AngularJS versions

Angular, released in 2016, is the TypeScript-based version of AngularJS. It is a complete rewrite with a component-based architecture, improved performance, and a more modern approach to web development using TypeScript for better type safety and tooling. It provides faster load times, improved scalability, and a more modular structure, making it the perfect choice for new projects.

Understanding the difference between Angular and AngularJS can provide valuable context as you begin your AngularJS journey and plan for future learning paths in front-end development.

Why should I choose AngularJS?#

Here are a few reasons why you should prefer AngularJS:

  • AngularJS is simpler and easier to pick up, especially for developers familiar with JavaScript but not TypeScript.

  • If you’re starting a new project, it’s generally recommended to use Angular, as it offers a more comprehensive set of features and better performance. However, if you’re maintaining an existing AngularJS application, you can continue to learn AngularJS.

  • For teams working on smaller projects that don’t require the heavy tooling and features of modern Angular (such as large-scale enterprise applications), AngularJS can provide a simpler, more lightweight framework.

  • AngularJS doesn’t rely on as many modern tools and package managers as Node.js, Webpack, or Angular CLI. For developers looking to avoid additional build steps, module systems, or dependency management, AngularJS is easier to set up and use out of the box with minimal configuration.

  • If a project requires compatibility with older browsers that may not fully support modern JavaScript features used by Angular, AngularJS could be a better choice.

Key concepts of AngularJS#

Let’s review some key concepts of AngularJS before we see how to use it to build a simple web application.

  • Modules: AngularJS applications are organized into modules, making grouping related components and services easy.

  • Controllers: Controllers manage the data and logic associated with a specific application part. They handle user interactions, update the view, and communicate with other application parts.

  • Directives: Directives are custom HTML attributes that extend the syntax of HTML to create reusable components. They can create new elements, modify existing elements, or control the data flow.

  • Services: These are reusable components that can be injected into other application parts. They often handle tasks like data fetching, validation, and communication with external APIs.

  • Data binding: AngularJS uses two-way data binding, which means that changes made to the model (data) are automatically reflected in the view and vice versa.

How can I set up AngularJS?#

Setting up AngularJS (the original AngularJS 1.x version) for your project is straightforward. There are two ways to do so.

How to set up AngularJS using a CDN#

A CDN is a quick way to include AngularJS in your project. It allows the application to fetch AngularJS from external servers.

<!DOCTYPE html>
<html lang="en">
<head>
<!-- Include AngularJS from a CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
.
.
.
</body>
</html>

In the above code, on line 5, we use the <script> tag to include version 1.8.2 of the AngularJS library from Google’s CDN. This library allows you to use the features of AngularJS, like directives and two-way data binding.

How to install AngularJS locally#

Another way to use AngularJS is by downloading it locally. This is useful for offline development. Here’s a step-by-step guide to setting it up:

  1. Download AngularJS from the official website of AngularJS or the GitHub repository of AngularJS.

  2. Include the downloaded file in the project folder and reference it in the HTML file.

<script src="path-to-angular/angular.min.js"></script>

This way, we can add the AngularJS library locally to the project.

How to create a “Hello World” app in AngularJS#

To create a simple AngularJS app, create a directory for the application. In this tutorial, our application directory is named angularjs-application. Now, follow these steps:

Step 1: Create an HTML file#

Inside the angularjs-application directory, create an HTML file named index.html to set up the basic HTML5 structure for our web page.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AngularJS App</title>
<!-- ... -->
</head>
<body>
<!-- ... -->
</body>
</html>

In the above code:

  • Lines 4–5: We specify the document’s character encoding and set the viewportViewport refers to the visible area of a web page on a device's screen. It determines how content is displayed and scaled based on the screen size and resolution. width and the initial zoom level.

  • Line 6: We set the title of the web page

Step 2: Include the AngularJS library via CDN#

After creating the index.html file, include the AngularJS library from a CDN. This will allow us to use AngularJS features in our application.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AngularJS App</title>
<!-- Include AngularJS Library -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
<!-- ... -->
</body>
</html>

Step 3: Create the JavaScript file#

Create a directory and name it js. Create the JavaScript file named app.js inside the js directory to define the AngularJS module and controller.

// Define the AngularJS module
var app = angular.module('myApp', []);
// Define a controller for the module
app.controller('MainController', function($scope) {
$scope.heading = 'Hello, World!';
$scope.message = 'Welcome to AngularJS!';
});

In the above code:

  • Line 2: We define an AngularJS module named myApp using the angular.module('myApp', []) function. The empty array [] indicates that this module has no dependencies.

  • Lines 5–8: We define MainController for the myApp module. The controller uses $scope, an object that binds the view (HTML) and the controller (JavaScript), when we assign the string Hello, World! to the $scope.heading variable and the string Welcome to AngularJS! to the $scope.message variable, the output is automatically updated.

Step 4: Include the AngularJS module and controller#

Include the custom JavaScript file in the index.html file and set up the controller.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AngularJS App</title>
<!-- Include AngularJS Library -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<!-- Include Custom JS file -->
<script src="js/app.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="MainController">
<h1>{{ heading }}</h1>
<p>{{ message }}</p>
</div>
</body>
</html>

In the above code:

  • Line 12: The <script> tag includes the custom JavaScript file.

  • Line 15: We use the ng-app="myApp" directive to initialize the AngularJS application and bind it to the <body> element. The ng-app directive tells AngularJS that this part of the page is controlled by the myApp module and serves as the starting point for the AngularJS application.

  • Line 16: We use the ng-controller="MainController" directive to bind the MainController (defined in the JavaScript file) to this part of the DOM. The ng-controller directive applies the logic and scope defined in the specified controller to this element and its children.

Project structure#

So far, the project structure should look like this:

angularjs-application/
├── index.html
└── js/
└── app.js
The directory structure of an AngularJS project

Demo#

We’ve successfully created the “Hello world” application in AngularJS. Click the “Run” button to see the output.

Next steps#

Congratulations! You’ve taken your first steps into the world of AngularJS. Here’s what you can do next:

  1. Practice, practice, practice! Try building a simple project like a music player application or a weather app.

  2. Dive deeper into AngularJS concepts like routing and custom directives.

  3. Explore related technologies like HTML5, CSS3, and JavaScript ES6. Visit this JavaScript ES6 Tutorial for a comprehensive guide to mastering modern JavaScript features, including arrow functions, template literals, classes, and more!

Remember, every expert was once a beginner. Keep coding, stay curious, and before you know it, you’ll be building amazing web applications!

Conclusion#

AngularJS remains a valuable tool for building dynamic web applications, especially for those looking to quickly learn and practice the fundamentals of front-end development. Its simplicity, two-way data binding, and modular approach make it an excellent choice for beginners and smaller projects. However, it’s important to recognize its limitations, including performance issues with large applications and the challenges of migrating to newer frameworks like Angular.

Frequently Asked Questions

How do I start learning Angular?

To start learning Angular:

  1. Understand the basics of web development, including HTML, CSS, JavaScript, and TypeScript, which is essential for Angular.
  2. Set up your environment by installing Node.js and Angular CLI, which streamline the development process.
  3. Follow the official Angular documentation to learn foundational concepts like components, templates, and data binding, and practice by building simple projects such as a to-do list or a calculator.
  4. Gradually explore advanced features like directives, services, dependency injection, and routing. Enhance your learning through online tutorials or courses and actively participate in the Angular developer community to stay updated and get support.

To streamline your learning, consider following the Zero to Hero in Front-End Development with Angular path on Educative. It’s designed to take you from beginner to expert with hands-on projects and practical lessons.

Is Angular easy to learn for beginners?

Can I learn Angular without JS?

How can I prepare for an interview for AngularJS?

How is AngularJS different from React?


Written By:
Rauf Tabassam
Join 2.5 million developers at
Explore the catalog

Free Resources