Tuesday, May 9, 2017

Angular JS

AngularJS is a very powerful JavaScript Framework. It is used in Single Page Application (SPA) projects. It extends HTML DOM with additional attributes and makes it more responsive to user actions. AngularJS is open source, completely free, and used by thousands of developers around the world. AngularJS version 1.0 was released in 2012 by Miško Hevery.AngularJS is a JavaScript framework.
It can be added to an HTML page with a <script> tag.


 

Let's look at a example.
  

javascript.js


index.html

Angular JS modules define applications.Module is a container for the different parts of an application.It is a container for the application controllers.A module is created using angular.module function.Here module name is myApp.[] is used for injecting dependencies.But here we keeps it empty.

var app = angular.module('myApp', []);

Angular JS controllers control applications. Controller is referring using ng-controller directive in HTML file.The ng-controller="myCtrl" attribute is an AngularJS directive. It defines a controller.Here $scope is the application object.Here controller creates two variables called firstName and lastname in the scope. ng-model directives bind the input fields to the controller.

app.controller('myCtrl', function($scope) {
    $scope.firstName= "Little";
    $scope.lastName= "John";
});

The AngularJS application is defined by  ng-app="myApp".AngularJS expressions can be written inside double braces.AngularJS will resolve the expression, and return the result exactly where the expression is written.Expressions are much like JavaScript expressions.Inside {{}} we can give mathematical expressions too.like {{5+5}}.AngularJS outputs the answer as 10.

No comments:

Post a Comment