Friday, March 17, 2017

Why Should I Use AngularJS?

There are lot of buzz going about AngularJS.  This article for rookies who wants to know what is AngularJS and why should we use it.

AngularJS is a JavaScript framework backed by Google.

What is a framework now ?


Framework is a set of tools where you can do specific tasks easier than generic tools programming languages. Some examples are

  • Bootstrap frameworks allows you to design beautiful web applications without writing a single CSS statement. 
  • A simple API can be built using ExpressJS framework for NodeJS without using any complex code.
  • Hibernate framework simplifies the trade offs between OOP and relation database

So the AngularJS is also a JavaScript framework. That means we can do many things easily using JavaScript and AngularJS.

What we are going to do ?

I have a simple html page. There I have a text box and a paragraph. What I want to do is, I want to appear the text in the text box in the paragraph. This should be done realtime. i.e: When user types something it should be on paragraph too.

Here is the HTML code

This is how it is done in JavaScript - Option 1

I have added few lines of Javascript after the body tag.


This is how it is done in jQuery(Another JS library) - Option 2

Here you must remove the onchange() attribute in text box. Somewhat simpler than raw JavaScript. Only one line inside the function.


Finally using AngularJS - Option 3

Here we do not have any Scripts or JavaScript functions. But I have added some extra attributes starting with ng-* to the text box and paragraph. Examine carefully the original and below. This does the same as above two methods. Did I wrote any Scripts ?? NO !!!. Saves time and LOCs. 

1 comment: