Introduction to AngularJS

Last Updated : 21 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

AngularJS is a popular open-source framework that simplifies web development by creating interactive single-page applications (SPAs). Unlike traditional websites that load new pages for each click, SPAs offer a smoother user experience by updating content on the same page.

AngularJS makes this possible by transforming static HTML into dynamic content that adapts to user interactions. Features like data binding and dependency injection streamline development, saving you time and effort. With regular updates and a large community, AngularJS ensures your web applications stay modern and efficient.

AngularJS is a JavaScript Framework

AngularJS is a JavaScript framework that can be used in 2 ways given below:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.3/angular.min.js" 
integrity="sha512-KZmyTq3PLx9EZl0RHShHQuXtrvdJ+m35tuOiwlcZfs/rE7NZv29ygNA8SFCkMXTnYZQK2OX0Gm2qKGfvWEtRXA=="
crossorigin="anonymous" referrerpolicy="no-referrer">
</script>

Why Choose AngularJS?

  1. Easy to Work With: AngularJS requires only basic knowledge of HTML, CSS, and JavaScript. You don’t need to be an expert; just bring your curiosity and creativity.
  2. Time-Saving Components: AngularJS allows you to work with reusable components, saving time and reducing unnecessary code. Components are the building blocks of your application.
  3. Ready-to-Use Templates: AngularJS leverages plain HTML templates, which it compiles and makes ready for use. No complex setup—just write your HTML and let AngularJS do the heavy lifting.
  4. Directives: AngularJS extends HTML with custom elements and attributes called directives. These enable you to create reusable components and define custom behaviors for your application. Directives make it easier to manipulate the DOM, handle events, and encapsulate complex UI logic within a single component.

Steps to Install Angular JS using Angular CLI

Step 1: Install the Angular CLI

npm install - g @angular/cli

Step-2: Initialize new project using the below command

ng new my-app

Step-3: Go to your project directory

cd my-app

Project Structure:

Angular JS Project structure

Step-4: Run the application using the following command in the terminal

ng serve 
Angular JS Introduction Page

Steps to Create First Angular App

Example: This example illustrates the basic Hello World app using Angular JS.

JavaScript
// Filename - app.component.ts

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

@Component({
  selector: 'my-app',
  template: '<h1>Hello World!</h1>',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
}

Output:

angular-js-first-app

Angula Hello World App

History of AngularJS

AngularJS was first developed in 2008-2009 by Miško Hevery and Adam Abrons at Brat Tech LLC. Its original purpose was to provide software for an online JSON storage service and simplify the development of enterprise applications that were valued by the megabyte. Currently, AngularJS is maintained by Google. Version 1.6, which introduced the concept of component-based application architecture, was the first release. This version removed the Sandbox, which was responsible for security, despite the fact that it had several vulnerabilities that could bypass it.

Key Features of AngularJS

  1. Model-View-Controller (MVC) Architecture:
    • Model: Manages data and logic, responding to requests from the view and instructions from the controller.
    • View: Displays application data to users.
    • Controller: Orchestrates communication between the model and view, updating the model based on user interactions.
  2. Filters and Data Transformation:
    • AngularJS provides powerful filters for transforming data before displaying it in templates. Common filters include filter, orderBy, and currency.
    • You can also create custom filters tailored to your application’s needs.
  3. Routing and Single-Page Applications (SPAs):
    • Implement client-side routing to create SPAs.
    • Handle route parameters and navigation seamlessly.
  4. Services and Dependency Injection:
    • Services are reusable components that provide specific functionality.
    • Dependency injection ensures loose coupling between components, making your code more maintainable.
  5. Custom Directives and Components:
    • Build reusable components using custom directives.
    • Isolate scope and communicate between components.
  6. Testing AngularJS Applications:
    • Write unit tests using Jasmine and Karma.
    • Explore end-to-end testing with Protractor.
  7. Advanced Topics:
    • Dive into promises and asynchronous programming.
    • Interact with RESTful APIs.
    • Optimize performance and follow best practices.

Applications of AngularJS

  1. Dynamic Forms:
    • AngularJS excels at creating dynamic forms with real-time validation and feedback.
  2. Real-Time Dashboards:
    • Build interactive dashboards that update in real time based on user interactions.
  3. Collaborative Apps:
    • AngularJS is perfect for chat applications and collaborative document editing.
  4. E-Commerce Platforms:
    • Create seamless shopping experiences with AngularJS-powered product catalogs and checkout processes.

Advantages of AngularJS

  • It facilitates the Two-way Binding that helps to render correspondingly the changes made to the view or the model.
  • It helps to create a responsive web application, along with providing the prototyping that can be utilized to load the application faster.
  • It uses the concept of directive that helps to add functionality to the application. For this, the overall length of the code reduces along with discarding the repetition of the code that is specific to perform the particular task.




Previous Article
Next Article

Similar Reads

AngularJS ng-show Directive
The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements. Syntax: &lt;element ng-show="expression"&gt; Contents... &lt;/element&gt; Parameter Value: expre
2 min read
Difference between Bootstrap and AngularJS
Bootstrap is a free and open source front-end web development framework. It is a giant collection of HTML, CSS, and JavaScript code that is designed to help build user interface components. It is a free collection of tools for creating websites and web applications. It is used by many developers and according to the official Bootstrap site: It is t
5 min read
How to append a new table row in AngularJS ?
In this article, we will see how to insert or append the new table row in AngularJS, along with knowing its implementation through the examples. Approach: The approach is to use the push() method to insert the new rows into the array. This array will be served as the content to the &lt;tr&gt; element. The ng-repeat directive is used to serve the co
2 min read
How to use a Custom Service Inside a Filter in AngularJS ?
AngularJS is a JavaScript-based framework. It can be used by adding it to an HTML page using a &lt;script&gt; tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. An Angular service is a broad category that consists of any value, function, or feature that an application
4 min read
AngularJS currency Filter
AngularJS currency filter is used to convert a number into a currency format. If no currency format is specified currency filter uses the local currency format. Syntax: {{ currency_expression | currency : symbol : fractionSize}}Parameters: It contains 2 parameters as mentioned above and described below: symbol: It is an optional parameter. It is us
2 min read
How to convert string into a number using AngularJS ?
In this article, we will see how to convert a string into a number in AngularJS, along with understanding its implementation through the illustrations. Approach: The parseInt() method is used for converting the string to an integer. We will check whether the string is an integer or not by the isNumber() method.Example 1: In the first example, the s
2 min read
How to encode/decode URL using AngularJS ?
In this article, we will see the mechanism to encode/decode URL using AngularJS, along with knowing the different methods available to accomplish the given task, &amp; will understand it through the illustration. A URL specifies a resource and its access protocol. Encode URL: URL Encoding is a way to translate unprintable or reserved characters in
3 min read
AngularJS ng-init Directive
The ng-init Directive is used to initialize AngularJS Application data. It defines the initial value for an AngularJS application and assigns values to the variables. The ng-init directive defines initial values and variables for an AngularJS application. Syntax: &lt;element ng-init = "expression"&gt; ... &lt;/element&gt;Example: This example descr
1 min read
AngularJS ng-if Directive
The ng-if Directive in AngularJS is used to remove or recreate a portion of the HTML element based on an expression. The ng-if is different from the ng-hide directive because it completely removes the element in the DOM rather than just hiding the display of the element. If the expression inside it is false then the element is removed and if it is
2 min read
AngularJS ng-dblclick Directive
The ng-dblclick Directive in AngluarJS is used to apply custom behavior when an element is clicked double. It can be used to show or hide some element or it can popup an alert or change the color of text when it is clicked twice. This means that the element's original ondblclick event will not be overridden by this directive, both will be executed.
2 min read
AngularJS ng-keypress Directive
The ng-keypress Directive in AngluarJS is used to apply custom behavior on a keypress event. It is mainly used to specify what to do when the keyboard is utilized with a particular HTML element. The order of sequence that the key is pressed is Keydown, Keypress, and keyup. It is supported by &lt;input&gt;, &lt;select&gt; and &lt;textarea&gt; elemen
2 min read
AngularJS ng-keydown Directive
The ng-keydown Directive in AngluarJS is used to apply custom behavior on a keydown event. This directive will not be overridden by the element's original onkeydown event. Both the onkeydown event &amp; the ng-keydown Directive will be executed. It is supported by &lt;input&gt;, &lt;select&gt; and &lt;textarea&gt; elements. Syntax: &lt;element ng-k
2 min read
AngularJS ng-keyup Directive
The ng-keyup Directive in AngluarJS is used to apply custom behavior on a keyup event. It is supported by &lt;input&gt;, &lt;select&gt; and &lt;textarea&gt; elements. Syntax: &lt;element ng-keyup="expression"&gt; Contents... &lt;/element&gt; Parameter: expression: When a keypress is finished, then the followed expression will be executed.Example 1:
2 min read
AngularJS ng-href Directive
The ng-href directive is used when we have an angular expression inside the href value. If href attribute is used then the problem is that if in case the link is clicked before AngularJS has replaced the expression with its value then it may go to the wrong URL and the link will be broken and will most likely return a 404 error while ng-href direct
2 min read
AngularJS ng-focus Directive
The ng-focus Directive in AngluarJS is used to apply custom behavior when an element is focused. It can be used to show/hide some element or it can pop up an alert when an element is being focused. It is supported by &lt;a&gt;, &lt;input&gt;, &lt;select&gt; and &lt;textarea&gt; elements. Syntax: &lt;element ng-focus="expression"&gt; Contents...
1 min read
AngularJS ng-hide Directive
The ng-hide Directive in AngluarJS is used to show or hide the specified HTML element. If the expression given in the ng-hide attribute is true then the HTML elements hide. In AngularJS there is a predefined class named ng-hide which is used to set the display to none. Syntax: &lt;element ng-hide="expression"&gt; Contents... &lt;/element&gt; Parame
2 min read
AngularJS ng-disabled Directive
In this article, we will see the AngularJS ng-disabled Directive, along with understanding its implementation through the illustrations. The ng-disabled Directive in AngularJS is used to enable or disable the HTML elements. If the expression inside the ng-disabled attribute returns true then the form field will be disabled or vice versa. It is usua
2 min read
AngularJS ng-list Directive
The ng-list Directive in AngularJS is used for separating input strings and converting them into an array of strings using a separator. By default, the comma is used as a default separator. But any custom separator can be used as the value of the ng-list directive. Syntax: &lt;element ng-list="delimiter"&gt; Contents... &lt;/element&gt; The value o
1 min read
AngularJS ng-mouseup Directive
The ng-mouseup Directive in AngularJS is used to apply custom behavior when a mouseup event occurs on a specific HTML element. It can be used to show a popup alert when the mouse button is pressed. The order of a mouse click is Mousedown, Mouseup, Click. It is supported by all HTML elements. Syntax: &lt;element ng-mouseup="expression"&gt; Contents.
2 min read
AngularJS ng-mousedown Directive
The ng-mousedown Directive in AngularJS is used to apply custom behavior when mousedown event occurs on a specific HTML element. It can be used to show a popup alert when the mouse button is pressed down. It is supported by all HTML elements. Syntax: &lt;element ng-mousedown="expression"&gt; Contents... &lt;/element&gt; Parameter: expression: When
1 min read
AngularJS ng-maxlength Directive
The ng-maxlength Directive in AngularJS is used to set the maximum length for an input field i.e it adds the restriction for an input field. It is different from maxlength attribute in HTML because the former prevents users from exceeding the limit whereas the later doesn't do that. It will make the form invalid if the input limit exceeds it. Synta
2 min read
AngularJS ng-minlength Directive
The ng-minlength Directive in AngularJS is used to set the minimum length for an input field i.e it adds the restriction for an input field. It is different from minlength attribute in HTML because the former prevents users from entering less than the specified limit whereas the later doesn't do that. It makes the form invalid if the entered input
2 min read
AngularJS ng-mouseover Directive
The ng-mouseover Directive in AngularJS is used to apply custom behavior when a mouseover event occurs on a specific HTML element. It can be used to show a popup alert when the mouse moves over a specific element. It is supported by all HTML elements. Syntax: &lt;element ng-mouseover="expression"&gt; Content... &lt;/element&gt;Parameter value: expr
2 min read
AngularJS Expressions
In this article, we will see the Expressions in AngularJS, along with understanding their implementation through the examples. Expressions in AngularJS are used to bind application data to HTML. The expressions are resolved by AngularJS and the result is returned back to where the expression is written. The expressions in AngularJS are written in d
2 min read
AngularJS ng-copy Directive
The ng-copy Directive in AngularJS is used to specify the custom behavior functions during the copy of the text in input text fields. It can be used when we want to call a function that will be triggered when the text is copied from the input field. It is supported by all input elements. The element's original oncopy event will not be overridden wi
2 min read
AngularJS ng-cut Directive
The ng-cut Directive in AngularJS is used to specify the custom behavior functions when the text in input fields is cut. It can be used when we want to call a function that will be triggered when the text is cut from the input field. It is supported by all input elements. Syntax: &lt;element ng-cut="expression"&gt; Contents... &lt;/element&gt;Param
2 min read
AngularJS ng-click Directive
The ng-click Directive in AngluarJS is used to apply custom behavior when an element is clicked. It can be used to show/hide some element or it can pop up an alert when the button is clicked. Syntax: &lt;element ng-click="expression"&gt; Contents... &lt;/element&gt;Parameter Value: expression: It specifies when the particular element is clicked the
2 min read
AngularJS ng-controller Directive
The ng-controller Directive in AngularJS is used to add a controller to the application. It can be used to add methods, functions, and variables that can be called on some event like click, etc to perform certain actions. Syntax: &lt;element ng-controller="expression"&gt; Contents... &lt;/element&gt; Parameter value: expression: It refers to the na
2 min read
AngularJS ng-checked Directive
The ng-checked Directive in AngularJS is used to read the checked or unchecked state of the checkbox or radio button to true or false. If the expression inside the ng-checked attribute returns true then the checkbox/radio button will be checked otherwise it will be unchecked. Syntax: &lt;input type="checkbox|radio" ng-checked="expression"&gt; Conte
2 min read
AngularJS ng-change Directive
The ng-change Directive in AngularJS is used whenever the value of an input element changes. The expression is evaluated immediately whenever there is a change in the input value. It requires an ng-model directive to be present. It is triggered whenever there is any single change in the input. It can be used with input elements like &lt;input&gt;,
2 min read