Total Pageviews

Thursday 28 April 2016

Hot Topic :: AngularJs vs jQuery


Its been a while when AngularJs came into the market and changing the era of browser based application development. Its already being liking by the developers and clients.

Before AngularJs :

  1. jQuery is used to manipulate and control DOM elements and also it solved the problems with IE , AJAX and made easier to deal with DOM elements.
  2. jQuery is a library mainly used for animation and AJAX.
  3. It’s lightweight and fast.
  4. Using this we can apply styles to UI to make UI attractive.
  5. As we know it’s a library so we can fully/partially or can no use inside our application.
  6. For creating a website jQuery is enough alone.
  7. It becomes complex when the size of project increases.
  8. To build a normal web app with less view and less user interactivity, should use jQuery.
After AngularJs :

  1.       AngularJs is a framework so while using it one should follow the rules of framework.
  2.      Used to create Single Page applications with lots of interactivity.
  3.          It’s a MVVM framework.
  4.          Its having 2 way data binding.
  5.          Containing directives to enhance DOM elements, built in as well as custom.
  6.          It is modular.
  7.          All features of jQuery is embedded in Angular called jqLite.
However, both are comes with a very different ideology. So there is no sense to compare them.
Still there is a brief difference i have written above to make few things clear about both.


Wednesday 27 April 2016

AngularJS : Simple Example of Adding Student Data Using Table

Below is a very simple example of AngularJS to explain few important directives which we gonna use from very start.

First, we need to know what are directives basically?
So, To enhance our HTML, AngularJs provides us some in built attributes called "Directives",  but we can also create our own directives which we will discuss later.

ng-app : This  initializes AngularJs application i.e. The first ng-app found in the document will automatically initializes application when web page is loaded. This defines a root element of an AngularJs  application.

ng-model : This binds the value of HTML element to application data. This binding goes both ways i.e. if value of HTML element is changed then AngularJs property automatically getting updated without refreshing a page.

ng-click : defines AngularJS code that will be executed when the element is being clicked. This directive comes under AngularJs Events.

ng-controller : The ng-controller directive defines the application controller,created by a standard JavaScript object constructor.
The StudentController function is a JavaScript function. AngularJS will invoke the controller with a $scope object which is the application object i.e. we can access any function and properties through this.
The controller creates properties in the scope.
The ng-model directives bind HTML elements to the controller properties.

In below example we can see the use of all the directives above explained in short obviously..;)

Example

<!doctype html>
<html ng-app>
<head>
<title>Simple TableRow Addition</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
</head>
<body ng-controller="StudentController">
<table>
<thead>
<tr>
<td>
<label> User: </label>
<input type="text" placeholder="Enter Name" ng-model="name" />
</td>
</tr>
<tr>
<td>
<label> Age: </label>
<input type="number" placeholder="Enter Age" ng-model="age" />
</td>
</tr>
<tr>
<td>
<label> Class: </label>
<input type="text" placeholder="Enter Class" ng-model="uclass" />
</td>
</tr>
</thead>
<td align="right">
<button type="button" ng-click="addUser()"> adduser </button>
</td>
</table>
<table border="1" cellpadding="10">
<thead>
<tr>
  <th>
 Name
  </th>
  <th>
 Age
  </th>
  <th>
 Title
  </th>
</tr>
</thead>
<body>
<tr ng-repeat="user in users">
  <td>
{{ user.name }}
 </td>
 <td>
{{ user.age }}
 </td>
 <td>
{{ user.uclass }}
 </td>
</tr>
</body>
</table>
<script>
function StudentController($scope)
{
$scope.users = [];

$scope.addUser = function(){
$scope.users.push({name : $scope.name,age:$scope.age,uclass:$scope.uclass});
}
}
</script>
</body>
</html>

Result : 



Tuesday 5 April 2016

A Very Common Question : Difference between $(document).ready, $(window).load

I just want to simplify the difference between these two JQuery functions.
So as far as i understood the things between two listed below :

Before writing difference just to mention few things if anyone doesn't know i.e.

"$"  is a way to access/define JQuery.
"(document)" inside bracket we mention HTML elements on which we want to perform some actions and specifically it is called as "selector".
And .ready is function which is called to perform action.

$(document).ready :  This event occurs once HTML document is loaded and DOM tree is created and JavaScript code ready to manipulate elements. 

  • HTML document : This is document based on HTML tags and provides special meaning to the texts written in between.
  • DOM tree : DOM tree is a cross platform and language independent hierarchy of elements associated inside the HTML page. This is itself is a vast topic of discussion so we will discuss this later in brief.
$(window).load :  This executes later, once all the content of document is fully loaded.

For Example : If there is document containing many images then $(document).ready will trigger without loading images but $(window).load will not fire until loading of all the images is not completed. 

Its a best practice to write all jquery functions inside document.ready.

Try to Check :

<html>
<head>
    <script src="jquery-1.9.1.min.js"></script>
    <script>
    $( document ).ready(function() 
    {
        alert( "document loaded" +Idev);
    });

    $( window ).load(function() 
    {
        alert( "window loaded" +Idev);
    });
    </script>
</head>
<body>
    <div id='Idev' src="https://www.blogger.com"></div>
</body>
</html>

Microsoft Logo using flexbox and Reactjs

 <!DOCTYPE html> <html> <head>     <script src="https://unpkg.com/react@18/umd/react.development.js" crossori...