• We Code
  • We Design
  • We Develope
  • We Write
  • We Share

menu

Thursday, August 22, 2013

Getting Started with Angular -My first angular program

0 comments
getting started with angular.js

Before we start developing in Angular you need to download Angular.js from its official page .It's available in both minfied and normal version .
Structure :
First we will look at the structure of the Angular.
<!doctype html>
<html ng-app>
  <body>
    ...
    <script src="angular.js">
  </body>
</html> 

The first line <!doctype html> is for the browser to make him aware about the page is HTML5 based .
The next tag is <html ng-app> the ng-app means your app will auto bootstrap or auto initialize .You can initialize the app manuallly also .
If you wanna get support on IE 7 or below also write it like this <html ng-app id="ng-app">.
One important thing we wrote the script tag at end of the body tag . The purpose of this is to let dom structure get ready . It is best practis

Now lets develope some thing . 

<!doctype html>
<html ng-app>
  <head>
  <title>My angular first program</title>
  </head>
  <body>
    <div>
      <label>Name:</label>
      <input type="text" ng-model="myMess" placeholder="Type any message here">
      <hr>
       <h1>it is your message {{myMess}}!</h1>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
  </body>
 </html>
Explanation : <input type="text" ng-model="myMess" placeholder="Type any message here">
Here we are declaring an input text type field . 
"ng-model" is Angular API which is responsible for two way data binding (binding view to the model).
It alow you the form validation like you normally does in HTML require ,url,number,email.We will review it in brief in future for now you just understand it is something related to the form

<h1>it is your message {{myMess}}!</h1> : this "{{ }}" is how we write expression in angular.{{myMess}} means  the value of [ ng-model="myMess" ] will be get displayed here . This is called two way data binding .
Read more ►

Tuesday, August 20, 2013

MVC in JavaScript Angular Vs Backbone vs Other

0 comments


One technology which did remarkably well in recent year is JavaScript (EcmaScript). From the concept of Oops JavaScript has moved to MVC. JavaScript had libraries like J query  which is all about  on  Dom manipulation . I spend last few months on MVC framework in JavaScript. Before discussing  the MVC frameworks of JavaScript lets first understand  what  MVC actually is in practical.   

What Is MVC , Or MV* means actually ?

Various frameworks make able developers to create   a flexible way to organizing their code by using the variations of a pattern called MVC (Model-View-Controller). This is what book speaks about MVC.
If you will dig deep  MVC. It is divided into three parts
MVC in JavaScript


Models represent the domain-specific knowledge and data in an application. Think of this as being a ‘type’ of data you can model — like a User, Photo or Note. Models should notify anyone observing them about their current state (e.g Views).
Views think of this as  User-interface  (e.g your markup and templates). Views must be aware about the structure of model but they need not to interact with model directly
Controllers takes the all input from user in the application and update the model. The  controller don’t directly communicate the view .
This is how the Model - View – Controller relation is .

Various MVC Frameworks
There are many JavaScript MVC frameworks available like Backbone.js, Knockout.js, Ember.js, Spine.js, Angular.js, Ext.js etc. The Framework which are on too much demand are Backbone.js and angular.js .Both have own positives and negatives. Let’s start reviewing the various MVC in JavaScript.
Backbone.Js  - If you are in the down town  of JavaScript you must heard its name a lot . This is the one of the most widely used MVC Framework, Backbone is flexible framework. It provide the flexibility to choose the feature which you want to implement and which you don’t .underscore .js is tightly integrated with this  . It plays very well with other frameworks .The first and main disadvantage I personally felt with Backbone is the bad documentation even though they improved it a lot but still it is not good enough for beginners. The functional drawback of backbone is it’s  don’t provide UI binding. It is a event driven framework.
backbone.js

Angular.js  - this is my personal  favorite framework .What is best about Angular.js  is it is not dependent on any other framework like underscore  jquery etc. If its Angular its pure Angular. Angular is a complete solution . In Backbone there you have to implement all the event listeners you need not to write for events listener or event trigger its automatically happens in angular. The both way data binding make it awesome. Angular is   heavy .It means you have to type less. 
Directives services and provider are good concepts.Directives helps keeps your DOM manipulation code in  angular element.It  allow app to concern for update only when the data changes by this developer can keep all view logic separate. The.The HTML 5 have a lot of new tags but directive helps you to invent your own html tag.
Filter is another good thing with Angular.Filter filter data before it reaches to the views.It can format data in decimal number,ascending and descending order Filter are similar to the Directives you can keep them standalone.

Service providers are other good feature of angular.Services are something like API which you keep outside from your controller and the service provider expose your controller to the service.It again help Developer to keep controller lightweight and do all heavy lifting out side the MVC.$brodacst and $emit are example of inbuilt services of angular.Emit will send message to all predecessor and broadcast will send message to all successor by definition.But both works pretty same in angular world.
Angular.js
ReactJS - ReactJS is open source JS library by Facebook.ReactJS is not MVC  but I am writing about it because people keep comparing Angular with React. Facebook guys created huge buzz on AngularVsReact. React Vs Angular does not make any sense for we guys.Angular is a complete framework on the other-hand React is just the view layer.React provides few functions to present the HTML.All the react output is HTML.
The react component is bundle of HTML and JAVASCRIPT. Their is concept of State and Props.Which comes from inside the component is state .The component save state it in memory.Which pushed in from outside is props.It is impossible to create an App alone on Reactjs

The good part of React:

1.A component lives his life in his life cycle.A component does not bother what other component is doing .Component himself understand what to render and where to render.
2.It is very easy to learn and understand the flow.
3.It always keeps the DOM shadow.It does not do to  entire DOM manipulation on data change instead it manipulate the particular DOM.
4.The Flow of Application is easily understandable.
ReactJs


The bad Part of React:

1.There is way to make AJAX call all alone in React i.e. Natwork layer is missing.
2.There is no data layer as well.
3.No promises available

4.Worst of all not enough Documentation



We will discuss more MVC frameworks and definitely Angular 2.0 in detail in future. Stay tuned.
Read more ►

Tuesday, August 6, 2013

how to write hello world programe in android using phonegap

0 comments
In The last blogpost we discused how to set the workspace for the android app developement in phonegap aka cordova.
In this post will write the "Hello world" programe for android using cordova .
So here are the steps for creating your first app in phonegap.
Step 1 : Set your work space as i wrote in last blogpost

Step 2 : Create a www & libs folder inside the Asset folder .

Step 3 : Create a js and css folder inside the www folder .

step 4 : create a index.html file inside the www folder .

Step 5 : Copy the cordova-2.7.0.jar file from downloaded phonegap folder to your projects asset/libs folder.

Step 6 : Right click on the cordova-2.7.0.jar file which you copied into asset/libs folder .A select menu will appear choose the "Buid Path" .And then select "Add To Build Path" .

Step 7 : Now copy the cordova-2.7.0.js file from downloaded phonegap folder to your projects asset/www/js folder.

Step 8 : Now open your index.html file from www folder . I assume you are familiar with web developement . make a reference of cordova-2.7.0.js in your index.html page. 

<script src="js/cordova-2.7.0.js" type="text/javascript"></script>

step 9 : Create a main.js file inside js folder . and refrence it in index .html page 

<script src="main.js" type="text/javascript"></script> 

Step 10: Write inside the body tag of index.html 
    <p>Hello World </p>

Step 11: Now Save all www folder files and Open the MainActivity.java file which you will found under the src folder.

Step 12: Keep the first line which start with "package" and  Remove the all other lines of that file .

Step 13: Copy the following lines in in the file .

  import android.os.Bundle;
import org.apache.cordova.*;
public class MainActivity extends DroidGap {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");
        
    }
   
}

Step 14:Now save the file . Clean the project . Build the project. Run the application . And you application is done .

Feel free to ask your doubts through comments  

Read more ►