AngularJS Framework

AngularJS is a very popular web application JavaScript framework. It is open source and used in Single Page Application (SPA). It extends HTML DOM attributes with Directives, and binds data to HTML with Expressions.

AngularJS Features:


Two way Data Binding is the awesome and most useful feature in AngularJS. AngularJS two-way data-binding handle the synchronization of data between model and view. Use ng-model directive to create two-way data-binding between the input element and view. Always the view projected model. The view appear the changes when the model change, and vice versa.


<html ng-app>
    <script src=""></script>
      <label>First Name:</label>
      <input type="text" ng-model="firstName" placeholder="Enter a First Name">
      <h1>My Name is, {{firstName}}!</h1>


AngularJS binds data to HTML using Expressions. Angular expressions are much like JavaScript code snippets that are usually placed in bindings such as {{ expression }}. 

Few of valid Angular expressions 

{{ 2 + 5 }}
{{ x + y }}
{{ x = 2 }}
{{ user.No }}
{{ items[index] }}


<html ng-app>
    <script src=""></script>
      <p>Total : {{ 5 + 5 }}</p>


AngularJS Directives is important AngularJS application components. AngularJS Directives allow us to extend the grammar of the web through reusable HTML elements, attributes, and classes.

ng-app - For starts an AngularJS Application.


<div ng-app="">
    <span>code here</code>

ng-init - Initializes application data.


<div ng-app="" ng-init="firstName='Roy'">
    <p>Name: <input type="text" ng-model="firstName"></p>
    <p>My Name: {{ firstName }}</p>

ng-model - Defines the model that is variable to be used in AngularJS.


<div ng-app="">
    <p>Enter your Name: <input type="text" ng-model="firstName"></p>

ng-repeat - Repeats html elements for each item in a collection.


<ul ng-controller='ProdController'>
    <li ng-repeat='product in Products'>{{}} - {{product.price}} </li> 
function ProdController($scope){ 
	$scope.Products = [
		{name: 'Mobile', price: 1000}, 
		{name: 'Desktop', price: 20000}

Views and routes:

AngularJS $route is used for linking URLs to controllers and views. It watches $location.url() and tries to map the path to an existing route definition.

var webApp = angular.module('webApp', ['ngRoute']);
myApp.config(['$routeProvider', function($routeProvider) {
	when('/products', { 
		templateUrl: 'views/products.html', 
		controller: 'ProdController'
		//default route
		redirectTo: '/index' 


AngularJS filter formats the value of an expression for display to the user.

List of commonly used filters.

  • currency
  • filter
  • lowercase
  • uppercase
  • orderBy


<div ng-app="">
    <p>First Name:<input type="text" ng-model="firstName"></p>
    <p>My Name in Upper Case: {{firstName | uppercase}}</p>


AngularJS form controls (input, select, textarea) are ways for a user to enter data.

For styling form fields have controls, ngModel adds these CSS classes:

  • ng-valid: model is valid
  • ng-invalid: model is invalid
  • ng-valid-[key]: for each valid key added by $setValidity
  • ng-invalid-[key]: for each invalid key added by $setValidity
  • ng-pristine: the control hasn't been interacted with yet
  • ng-dirty: the control has been interacted with
  • ng-touched: the control has been blurred
  • ng-untouched: the control hasn't been blurred
  • ng-pending: any $asyncValidators are unfulfilled


<div ng-app="webApp" ng-controller="formController">
  <form novalidate>
    First Name:<br>
    <input type="text" ng-model="emp.firstName"><br>
    Last Name:<br>
    <input type="text" ng-model="emp.lastName">
    <button ng-click="reset()">Reset</button>
  <p>form = {{emp}}</p>
  <p>master = {{master}}</p>
var app = angular.module('webApp', []);
app.controller('formController', function($scope) {
    $scope.master = {firstName: "Roy", lastName: "Mathew"};
    $scope.reset = function() {
        $scope.emp = angular.copy($scope.master);