Monday, March 9, 2015

AngularJs Data Binding

AngularJS takes a different approach. Instead of merging data into a template and replacing a DOM element, AngularJS creates live templates as a view. Individual components of the views are dynamically interpolated live. This feature is arguably one of the most important in AngularJS and allows us to write the hello world app we just wrote in only 10 lines of code without a single line of JavaScript.

This feature works by simply including angular.js in our HTML and explicitly setting the ng-app attribute on an element in the DOM. The ng-app attribute declares that everything inside of it belongs to this Angular app; that’s how we can nest an Angular app inside of a web app. The only components that will be affected by Angular are the DOM elements that we declare inside of the one with the ng-app attribute.

AngularJS 'Hello world' example

<!DOCTYPE html>
<html ng-app>
<head>
<title>Simple app</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js">
</script>
</head>
<body>
<input ng-model="name" type="text" placeholder="Your name">
<h1>Hello {{ name }}</h1>
</body>
</html>

Wednesday, January 14, 2015

Getting started with AngularJs

I have been working as UI developer for previous 7 years on various projects with server side languages like Java, .net, PHP. Seriously telling you before jumping into AngularJs my UI developer life was very easy, but as soon as I adopted AngularJs my work load and responsibilities increased more than double. AngularJs has reduced server side coding and made it possible to manage lots of backend efforts on frontend, but working on AngularJs is really a great experience. I bet after learning AngularJs you'll forget other scripting languages.

AngularJs has enabled us to communicate between server and client side without using JSP, XSLT, ASPX(.net) pages, AngularJs has made it as easy as developing a complete project with simple HTML, CSS and JavaScript.

AngularJS makes it incredibly easy to build web applications, it also makes it easy to build complex applications. AngularJS takes care of advanced features that users have become accustomed to in modern web applications, such as:
  • Separation of application logic, data models, and views
  • Ajax services
  • Dependency injection
  • Browser history (makes bookmarking and back/forward buttons work like normal web apps)
  • Testing
  • And more

 

How Is It different?

In other JavaScript frameworks, we are forced to extend from custom JavaScript objects and manipulate the DOM from the outside in. For instance, using jQuery, for

example suppose we have following HTML code, and we want to add the text 'Naren' to the span 'Hello' when entered the value in text box:
<div>
    <input id="name" type="text" />
    <span id="greeting">Hello</span>
</div>

Now look into jQuery way:
//look up the input element
var name = $('#name');
//look up the output element
var greeting = $('#greeting');
//listen for keyboard events
name.keyup(function() {
        //update the output element with the new input
        greeting.text('Hello ' + name.val());
});

Now with AngularJs:
<div ng-app>
    <input type="text" ng-model="name" />
    <span>Hello {{name}}</span>
</div>
That's it no more lines of extra script.

Readers! keep reading my posts there is lots of UI Developr stuff to be share with you.



2 days' AngularJs training classes are going on with me for professional UI Developers. You can enroll by a phone call at +91 987 143 3826 or eMail me at mr.nsjayas@gmail.com or visit www.oyetrade.com.