Angular JS Introduction



Angular JS

Today I'm going to give introduction to world's most popular web framework Angular JS. Actually its complete client side framework. Where it can design UI, client side programming, Connecting with Server with http services. So this is very important JavaScript based framework. And also it is developed by Google. As to date which i'm writing this blog, There is a new version of Angular JS named Angular 2. Its based on TypeScript which a supertype of JavaScript where developed by Microsoft. However, I will focus on angular JS 1.x

Lets get into angular JS.

Angular JS is stick in MVC (Model View Controler) architecture. That is one of reason to becoming it's popularity. So, In angular JS, There are 3 main parts.
Module
Views
Controlers

Module

Just forget about angular Js and think about module In MVC architecture. Its represent an entity, a database. So the concept is data handling. Thats the thing doing in Angular JS too. In html forms like things, there are some values. They might be user entered or can be even auto generated. Module will grab (bind) that data into variables created in Angular JS so that we can manipulate (handle) that values.

we can specify module by this way

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

[] means, this is new module. If we need some dependencies, we will inject into that. In example, To handle angular routing, We need to use angular-route. So to work our module with that, we will inject angular route into our module like below.

var myModule = angular.module('myModule', ['ngRoute']);

to use angular module in our html page, we use ng-app directive like below

<!DOCTYPE html>
<html>
        <head>
             <title>
             </title>
        </head>
        <body ng-app="myModule">
        </body>
</html>

Controller

This will handle business logic part of Angular module. We will inject a variable named $scope to controller to communicate between html page and controller.


I will demonstrate small example to how controller work. This is the application which I going to implement. The things in textbox will automatically show above <h2> tag. With preposition of Welcome.

first of all, we need to create a module.





Then create controller
Now Implement html page to work with above things
So the whole code will look like below







Views

Angular views are used to make SPA (Single Page Applications) using Angular JS. Basic idea of view is there is a div in html page and that div is working as a place holder for another web pages. We can load any web page into that div. That is view. We have given a directive by angular js to define that placeholder div. its ng-view. And also we need to use angular route to manage routes to pages that loads into view.

I'm not going to describe much about angular view because, I think its better to describe angular view in another tutorial with more details.

More than Module, Controller and View, There are many more things in Angular JS like services, Directives etc... I will go detailed about them in a next tutorial.

Meanwhile, You can read this references.

https://www.w3schools.com/angular/default.asp

https://docs.angularjs.org/api


I hope you were got some thing from this tutorial. Thank you for reading this.


Good Bye!!

Comments

Popular posts from this blog

CSRF Defence - Synchronizer Token Pattern Demo

Lets read emails in gmail using oAuth 2.0 (Application demo)

How to view queries executed in MySQL?