<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UnderscoreJs &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/underscorejs/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Sat, 05 Jul 2014 19:18:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>Pagination, Searching and Sorting of Data Table  using AngularJS</title>
		<link>https://www.jitendrazaa.com/blog/webtech/web/pagination-and-sorting-of-data-table-using-angularjs/</link>
					<comments>https://www.jitendrazaa.com/blog/webtech/web/pagination-and-sorting-of-data-table-using-angularjs/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra Zaa]]></dc:creator>
		<pubDate>Sat, 22 Feb 2014 03:29:20 +0000</pubDate>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[AngularJs]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Underscore]]></category>
		<category><![CDATA[UnderscoreJs]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=3751</guid>

					<description><![CDATA[We have already discussed &#8220;Basics of AngularJS&#8221; and &#8220;Simple Searching and Sorting&#8220;. In this article, we will add Pagination feature also to our previous example. What makes difficult is Sorting result when values are returned from Search and pagination is enabled. Unlike previous post we cannot use standard &#8220;OrderBy&#8221; filter provided by AngularJs framework, this [&#8230;]]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">We have already discussed &#8220;<a title="Basics of AngularJs" href="https://jitendrazaa.com/blog/webtech/web/getting-started-with-angularjs/">Basics of AngularJS</a>&#8221; and &#8220;<a title="Simple Searching and Sorting using AngularJs" href="https://jitendrazaa.com/blog/webtech/web/table-with-sorting-and-searching-using-angularjs/">Simple Searching and Sorting</a>&#8220;. In this article, we will add Pagination feature also to our <a title="Searching and Sorting in AngularJs" href="https://jitendrazaa.com/blog/webtech/web/table-with-sorting-and-searching-using-angularjs/">previous example</a>. What makes difficult is Sorting result when values are returned from Search and pagination is enabled. Unlike previous post we cannot use standard &#8220;<a title="OrderBy AngularJs" href="http://docs.angularjs.org/api/ng/filter/orderBy">OrderBy</a>&#8221; filter provided by AngularJs framework, this time we have to create Javascript function inside Controller for Sorting purpose.</p>
<p>Prerequisite Libraries :</p>
<ol>
<li><a title="UnderscoreJs Library" href="http://underscorejs.org/underscore.js">UnderscoreJs</a></li>
<li><a title="Bootstrap library" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">Bootstrap CSS</a></li>
<li><a title="AngularJs library" href="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js">AngularJs</a></li>
</ol>
<p style="text-align: justify;">This post used &#8220;Custom Service&#8221;, so please read <a title="Dependency Injection in AngularJs" href="https://jitendrazaa.com/blog/webtech/web/dependency-injection-in-angularjs/">this article</a> to understand Dependency Injection in AngularJs.</p>
<figure id="attachment_3753" aria-describedby="caption-attachment-3753" style="width: 300px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2014/02/Searching-Sorting-and-Pagination-in-Table-using-AngularJS.png?ssl=1"><img data-recalc-dims="1" decoding="async" class="size-medium wp-image-3753" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2014/02/Searching-Sorting-and-Pagination-in-Table-using-AngularJS-300x156.png?resize=300%2C156&#038;ssl=1" alt="Searching Sorting and Pagination in Table using AngularJS" width="300" height="156" /></a><figcaption id="caption-attachment-3753" class="wp-caption-text">Searching Sorting and Pagination in Table using AngularJS</figcaption></figure>
<p><span id="more-3751"></span></p>
<p><strong>Live Demo :</strong></p>
<p><iframe src="http://jsfiddle.net/ilovenagpur/wPnxy/embedded/result/" width="96%" height="450" frameborder="0" scrolling="no"></iframe></p>
<p><strong>Complete HTML Code :</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;br /&gt;
&lt;br /&gt;
&lt;div ng-app=&quot;myApp&quot;&gt;
    &lt;div ng-controller=&quot;TableCtrl&quot;&gt;
        &lt;div class=&quot;input-group&quot;&gt;
            &lt;input class=&quot;form-control&quot; ng-model=&quot;searchText&quot; placeholder=&quot;Search&quot; type=&quot;search&quot; ng-change=&quot;search()&quot; /&gt; &lt;span class=&quot;input-group-addon&quot;&gt;
      &lt;span class=&quot;glyphicon glyphicon-search&quot;&gt;&lt;/span&gt;
&lt;/span&gt;
        &lt;/div&gt;
        &lt;table class=&quot;table  table-hover data-table myTable&quot;&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th class=&quot;EmpId&quot;&gt; &lt;a href=&quot;#&quot; ng-click=&quot;sort('EmpId',$event)&quot;&gt;EmpId
                         &lt;span class=&quot;{{Header&#x5B;0]}}&quot;&gt;&lt;/span&gt;
                         &lt;/a&gt;

                    &lt;/th&gt;
                    &lt;th class=&quot;name&quot;&gt; &lt;a ng-click=&quot;sort('name')&quot; href=&quot;#&quot;&gt; Name
                         &lt;span class=&quot;{{Header&#x5B;1]}}&quot;&gt;&lt;/span&gt;&lt;/a&gt;
                    &lt;/th&gt;
                    &lt;th class=&quot;Email&quot;&gt; &lt;a ng-click=&quot;sort('Email')&quot; href=&quot;#&quot;&gt; Email
                     &lt;span class=&quot;{{Header&#x5B;2]}}&quot;&gt;&lt;/span&gt;&lt;/a&gt;
                    &lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
                &lt;tr ng-repeat=&quot;item in ItemsByPage&#x5B;currentPage] | orderBy:columnToOrder:reverse&quot;&gt;
                    &lt;td&gt;{{item.EmpId}}&lt;/td&gt;
                    &lt;td&gt;{{item.name}}&lt;/td&gt;
                    &lt;td&gt;{{item.Email}}&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/tbody&gt;
        &lt;/table&gt;
        &lt;ul class=&quot;pagination pagination-sm&quot;&gt;
            &lt;li ng-class=&quot;{active:0}&quot;&gt;&lt;a href=&quot;#&quot; ng-click=&quot;firstPage()&quot;&gt;First&lt;/a&gt;

            &lt;/li&gt;
            &lt;li ng-repeat=&quot;n in range(ItemsByPage.length)&quot;&gt; &lt;a href=&quot;#&quot; ng-click=&quot;setPage()&quot; ng-bind=&quot;n+1&quot;&gt;1&lt;/a&gt;

            &lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot; ng-click=&quot;lastPage()&quot;&gt;Last&lt;/a&gt;

            &lt;/li&gt;
        &lt;/ul&gt;
        &lt;div class=&quot;row&quot;&gt;
            &lt;div class=&quot;col-xs-3&quot;&gt;
                &lt;input type=&quot;text&quot; ng-model=&quot;newEmpId&quot; class=&quot;form-control&quot; placeholder=&quot;EmpId&quot;&gt;
            &lt;/div&gt;
            &lt;div class=&quot;col-xs-3&quot;&gt;
                &lt;input type=&quot;text&quot; ng-model=&quot;newName&quot; class=&quot;form-control&quot; placeholder=&quot;Name&quot;&gt;
            &lt;/div&gt;
            &lt;div class=&quot;col-xs-4&quot;&gt;
                &lt;input type=&quot;email&quot; ng-model=&quot;newEmail&quot; class=&quot;form-control&quot; placeholder=&quot;Email&quot;&gt;
            &lt;/div&gt;
            &lt;div class=&quot;col-xs-1&quot;&gt;
                &lt;button ng-click=&quot;add()&quot; type=&quot;button&quot; class=&quot;btn btn-primary&quot;&gt; &lt;span class=&quot;glyphicon glyphicon-plus&quot;&gt;&lt;/span&gt;

                &lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;!-- Ends Controller --&gt;
&lt;/div&gt;
</pre>
<p><strong>Complete JavaScript Code :</strong></p>
<pre class="brush: jscript; title: ; notranslate">
//Demo of Searching Sorting and Pagination of Table with AngularJS - Advance Example

var myApp = angular.module('myApp', &#x5B;]);

//Not Necessary to Create Service, Same can be done in COntroller also as method like add() method
myApp.service('filteredListService', function () {

    this.searched = function (valLists, toSearch) {
        return _.filter(valLists,

        function (i) {
            /* Search Text in all 3 fields */
            return searchUtil(i, toSearch);
        });
    };

    this.paged = function (valLists, pageSize) {
        retVal = &#x5B;];
        for (var i = 0; i &lt; valLists.length; i++) {
            if (i % pageSize === 0) {
                retVal&#x5B;Math.floor(i / pageSize)] = &#x5B;valLists&#x5B;i]];
            } else {
                retVal&#x5B;Math.floor(i / pageSize)].push(valLists&#x5B;i]);
            }
        }
        return retVal;
    };

});

//Inject Custom Service Created by us and Global service $filter. This is one way of specifying dependency Injection
var TableCtrl = myApp.controller('TableCtrl', function ($scope, $filter, filteredListService) {

    $scope.pageSize = 4;
    $scope.allItems = getDummyData();
    $scope.reverse = false;

    $scope.resetAll = function () {
        $scope.filteredList = $scope.allItems;
        $scope.newEmpId = '';
        $scope.newName = '';
        $scope.newEmail = '';
        $scope.searchText = '';
        $scope.currentPage = 0;
        $scope.Header = &#x5B;'', '', ''];
    }

    $scope.add = function () {
        $scope.allItems.push({
            EmpId: $scope.newEmpId,
            name: $scope.newName,
            Email: $scope.newEmail
        });
        $scope.resetAll();
    }

    $scope.search = function () {
        $scope.filteredList = filteredListService.searched($scope.allItems, $scope.searchText);

        if ($scope.searchText == '') {
            $scope.filteredList = $scope.allItems;
        }
        $scope.pagination();
    }

    // Calculate Total Number of Pages based on Search Result
    $scope.pagination = function () {
        $scope.ItemsByPage = filteredListService.paged($scope.filteredList, $scope.pageSize);
    };

    $scope.setPage = function () {
        $scope.currentPage = this.n;
    };

    $scope.firstPage = function () {
        $scope.currentPage = 0;
    };

    $scope.lastPage = function () {
        $scope.currentPage = $scope.ItemsByPage.length - 1;
    };

    $scope.range = function (input, total) {
        var ret = &#x5B;];
        if (!total) {
            total = input;
            input = 0;
        }
        for (var i = input; i &lt; total; i++) {
            if (i != 0 &amp;&amp; i != total - 1) {
                ret.push(i);
            }
        }
        return ret;
    };

    $scope.sort = function (sortBy) {
        $scope.resetAll();

        $scope.columnToOrder = sortBy;

        //$Filter - Standard Service
        $scope.filteredList = $filter('orderBy')($scope.filteredList, $scope.columnToOrder, $scope.reverse);

        if ($scope.reverse) iconName = 'glyphicon glyphicon-chevron-up';
        else iconName = 'glyphicon glyphicon-chevron-down';

        if (sortBy === 'EmpId') {
            $scope.Header&#x5B;0] = iconName;
        } else if (sortBy === 'name') {
            $scope.Header&#x5B;1] = iconName;
        } else {
            $scope.Header&#x5B;2] = iconName;
        }

        $scope.reverse = !$scope.reverse;

        $scope.pagination();
    };

    //By Default sort ny Name
    $scope.sort('name');

});

function searchUtil(item, toSearch) {
    /* Search Text in all 3 fields */
    return (item.name.toLowerCase().indexOf(toSearch.toLowerCase()) &gt; -1 || item.Email.toLowerCase().indexOf(toSearch.toLowerCase()) &gt; -1 || item.EmpId == toSearch) ? true : false;
}

/*Get Dummy Data for Example*/
function getDummyData() {
    return &#x5B;{
        EmpId: 2,
        name: 'Jitendra',
        Email: 'jz@gmail.com'
    }, {
        EmpId: 1,
        name: 'Minal',
        Email: 'amz@gmail.com'
    }, {
        EmpId: 3,
        name: 'Rudra',
        Email: 'ruz@gmail.com'
    }, {
        EmpId: 21,
        name: 'Jitendra1',
        Email: 'jz@gmail.com'
    }, {
        EmpId: 11,
        name: 'Minal1',
        Email: 'amz@gmail.com'
    }, {
        EmpId: 31,
        name: 'Rudra1',
        Email: 'ruz@gmail.com'
    }, {
        EmpId: 22,
        name: 'Jitendra2',
        Email: 'jz@gmail.com'
    }, {
        EmpId: 12,
        name: 'Minal2',
        Email: 'amz@gmail.com'
    }, {
        EmpId: 32,
        name: 'Rudra2',
        Email: 'ruz@gmail.com'
    }, {
        EmpId: 23,
        name: 'Jitendra3',
        Email: 'jz@gmail.com'
    }, {
        EmpId: 13,
        name: 'Minal3',
        Email: 'amz@gmail.com'
    }, {
        EmpId: 33,
        name: 'Rudra3',
        Email: 'ruz@gmail.com'
    }];
}
</pre>
<p style="text-align: justify;">JSON data is input to table, which can be replaced by any server side JSON response. So, in case if you need to use this example in <em>Salesforce</em>, You simply have to change &#8220;<em>getDummyData()</em>&#8220; method and get response using REST API. <a title="Get JSON Output in Visualforce Page" href="https://jitendrazaa.com/blog/salesforce/json-output-in-visualforce/">This article will be helpful if you are looking on how to generate JSON output in Visualforce page</a>.</p>
<p style="text-align: justify;"><a title="Dependency Injection in AngularJs" href="https://www.jitendrazaa.com/blog/webtech/web/dependency-injection-in-angularjs/"><strong>Why do we need Service in above example ?</strong></a></p>
<p style="text-align: justify;">It is always better to separate concern from Controller. So instead of writing methods or logics inside Controller, we have created Service and passed service as a parameter while declaring controller.</p>
<p style="text-align: justify;">Now we just have to call methods declared in service from Controller.</p>
<p style="text-align: justify;">If you are looking for same kind of Example in <a title="Salesforce" href="https://jitendrazaa.com/blog/tag/salesforce/">Salesforce </a>then this is <a title="Getting started with Angular.Js with Salesforce Visualforce Pages" href="http://www.oyecode.com/2013/06/getting-started-with-angularjs-on.html">very Good Article</a> written by <a title="Harshit Pandey" href="https://plus.google.com/+HarshitPandey/posts">Harshit </a>and <a title="Mohit Srivastav" href="https://plus.google.com/+mohitsrivastav/posts">Mohit Srivastav</a>.</p>
<p><strong><a title="Live Demo of Pagination, Sorting and Searching of Datatable in AngularJs" href="http://jsfiddle.net/ilovenagpur/wPnxy/">Live Demo of this example</a></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/webtech/web/pagination-and-sorting-of-data-table-using-angularjs/feed/</wfw:commentRss>
			<slash:comments>20</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3751</post-id>	</item>
		<item>
		<title>Getting Started with AngularJs</title>
		<link>https://www.jitendrazaa.com/blog/webtech/web/getting-started-with-angularjs/</link>
					<comments>https://www.jitendrazaa.com/blog/webtech/web/getting-started-with-angularjs/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Sat, 15 Feb 2014 02:56:39 +0000</pubDate>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[AngularJs]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Underscore]]></category>
		<category><![CDATA[Underscore.js]]></category>
		<category><![CDATA[UnderscoreJs]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=3675</guid>

					<description><![CDATA[AngularJs is most accepted MVC framework in Javascript developed by Google. In my point of view, If its developed by Google then there must be something new and unique about this library. It can be used to provide MVC architect to your web application. It has great developers community, so if you are stucked somewhere while using [&#8230;]]]></description>
										<content:encoded><![CDATA[<figure id="attachment_3676" aria-describedby="caption-attachment-3676" style="width: 300px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2014/02/AngularJS-by-Google.png?ssl=1"><img data-recalc-dims="1" decoding="async" class="size-medium wp-image-3676" alt="AngularJS by Google" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2014/02/AngularJS-by-Google-300x84.png?resize=300%2C84&#038;ssl=1" width="300" height="84" /></a><figcaption id="caption-attachment-3676" class="wp-caption-text">AngularJS by Google</figcaption></figure>
<p style="text-align: justify;"><a title="AngularJs Documentation" href="http://docs.angularjs.org/guide/">AngularJs </a>is most accepted MVC framework in Javascript developed by Google. In my point of view, If its developed by Google then there must be something new and unique about this library. It can be used to provide MVC architect to your web application. It has great developers community, so if you are stucked somewhere while using this library, you will have tons of supporters.</p>
<p style="text-align: justify;"><strong>So what is so special about this framework, other than its developed by Google ?</strong></p>
<ul>
<li>Unlike <a title="Backbone Js" href="http://backbonejs.org/">Backbone </a>and <a title="EmberJs Framework" href="http://emberjs.com/">Ember</a>, You don&#8217;t have to spend time on Event Handling (Bind, UnBind Events etc).</li>
<li>It Works on principal of Dirty Checking.</li>
<li>Automatically fires event if something gets changed.</li>
</ul>
<p style="text-align: justify;"><strong>What ? Dirty checking ? wouldn&#8217;t it be performance impact on my web application?</strong></p>
<p style="text-align: justify;">You are correct. But Google team has answer for this.</p>
<ul>
<li>AngularJS performance mainly linked to your computer (Client&#8217;s Computer) performance.</li>
<li>Ergonomical point of view, an HTML page should not have more than 200 fields. More fields will just distract users.</li>
</ul>
<p style="text-align: justify;">In this article, I will demonstrate how to use AngularJs framework to create simple application.<span id="more-3675"></span></p>
<p>Application will look like :</p>
<figure id="attachment_3677" aria-describedby="caption-attachment-3677" style="width: 300px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2014/02/Getting-Started-with-AngularJs.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-medium wp-image-3677" alt="Getting Started with AngularJs" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2014/02/Getting-Started-with-AngularJs-300x195.png?resize=300%2C195&#038;ssl=1" width="300" height="195" /></a><figcaption id="caption-attachment-3677" class="wp-caption-text">Getting Started with AngularJs</figcaption></figure>
<p style="text-align: justify;">We have already discussed about <a title="How to use Underscore - Getting Started" href="https://jitendrazaa.com/blog/salesforce/client-side-templating-using-underscore-js-and-jquery/" target="_blank">using underscore library</a> for javascript collection related utilities and templating in previous article. In this demo also, I have used this library to clear list of items which are checked using method &#8220;<a title="filter method in UnderscoreJs" href="http://underscorejs.org/#filter">filter</a>&#8220;.</p>
<p style="text-align: justify;"><a title="Live Demo of AngularJs application" href="http://jsfiddle.net/ilovenagpur/uWvN6/embedded/result/">Live Demo of application</a></p>
<p style="text-align: justify;"><!--more--></p>
<p style="text-align: justify;">HTML Code :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;body ng-app&gt;
    &lt;h2&gt; Angular Demo with BootStrap and Underscore.js&lt;/h2&gt;

    &lt;div ng-controller=&quot;ItemCtrl&quot;&gt;
          Total Items -  {{items.length}}
        &lt;ul class=&quot;unstyled&quot;&gt;
            &lt;li ng-repeat=&quot;item in items&quot;&gt;
                &lt;input type=&quot;checkbox&quot; ng-model=&quot;item.done&quot;&gt;
                    &lt;span class=&quot;done-{{item.done}}&quot;&gt; {{item.txt}} &lt;/span&gt;
            &lt;/li&gt;
        &lt;/ul&gt;

            &lt;form class=&quot;form-horizontal&quot;&gt;
                 &lt;div class=&quot;form-group&quot;&gt;
                    &lt;input type=&quot;text&quot; ng-model=&quot;itemToAdd&quot;   placeHolder=&quot;Add Item&quot;/&gt;
                    &lt;button   class=&quot;btn&quot; ng-click=&quot;add()&quot;&gt;
                        &lt;i class=&quot;icon-plus-sign&quot;&gt;&lt;/i&gt;  Add
                    &lt;/button&gt;
                &lt;/div&gt;
                &lt;button class=&quot;btn&quot; ng-click=&quot;clear()&quot;&gt;
                    &lt;i class=&quot;icon-trash&quot;&gt;&lt;/i&gt; Clear Completed Items
                &lt;/button&gt;
            &lt;/form&gt;
    &lt;/div&gt;
&lt;/body&gt;
</pre>
<p>JavaScript code :</p>
<pre class="brush: jscript; title: ; notranslate">
function ItemCtrl($scope)
{

  $scope.items = &#x5B;
    {txt:&quot;Angular is Awsome&quot;, done:false},
    {txt:&quot;Next is Node.js&quot;, done:false}
  ];

  $scope.add = function() {
  $scope.items.push({txt:$scope.itemToAdd,done:false});
		$scope.itemToAdd = &quot;&quot;;
  }

  $scope.clear = function(){
    //Here we will use Underscore as simplest library to work with Collections
    $scope.items = _.filter($scope.items, function(item){
    return !item.done;
  });
}
}
</pre>
<p>For look and Feel we are using <a title="Bootstrap by Tweeter" href="http://getbootstrap.com/css/">Tweeter&#8217;s Bootstrap library</a>.</p>
<p>Additional CSS :</p>
<pre class="brush: css; title: ; notranslate">
.done-true {
    text-decoration:line-through;
    color:grey;
}
</pre>
<p>Output of above code is already shown above.</p>
<p>Now Lets understand above code and few basics of AngularJs.</p>
<p><strong>How to define variables ?</strong></p>
<p>Variable can be used in HTML as well as javascript part of your application. Inside Javascript, you can use it normally, however if you want to use any variable inside HTML (View) then your variable has to be enclosed between <strong>double curly bracket</strong>.</p>
<p>Lets take other example to understand this.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;body ng-app&gt;
  &lt;p&gt;Hello {{name}}&lt;/p&gt;
  &lt;input type=&quot;text&quot; ng-model=&quot;name&quot;&gt;
&lt;/body&gt;
</pre>
<p>As shown in above code, &#8220;name&#8221; is variable. Without single line of javascript code, your angularJs will understand that whatever entered inside text box has to be updated in &lt;p&gt; tag. If you see, we have not added any onchange event on textbox. It all works automatically on principal of dirty checking, Isn&#8217;t it so cool ? 🙂</p>
<p><a title="Run AngularJs without single line of Javascript ode" href="http://jsfiddle.net/ilovenagpur/55hm7/">Working demo of above example</a>.</p>
<p>Lets come back to our original code. If you see HTML part, we have used many variables like {{item.length}} and it is defined in JavaScript code.</p>
<p><strong>What is Angular application or &#8220;ng-app&#8221; ?</strong></p>
<p>Your web page can have one or many application defined by tag &#8220;ng-app&#8221;. This represents one unit of application which will have its own controller. In order to use AngularJs, you must need to have atleast one ng-app.</p>
<p>Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application.</p>
<p><strong>What is Controller ?</strong></p>
<p>Controller will decide that what action has to perform on part of your web application. It Controls flow of execution and logic.</p>
<p>This is defined with help of attribute &#8220;<strong>ng-controller</strong>&#8220;. This is actually Engine Directive used to define Controller. $scope variables can be accessed only between its definition. In our Example, we have defined controller by name &#8220;ItemCtrl&#8221;. In Simple words you can say that Controller is plain javaScript function where you define your data to visible in scope and operations to be performed.</p>
<p>There are many ways to define controller. One of the simplest way, which I followed in this example is to define normal javaScript function and supply $scope argument.</p>
<p>Inside Controller &#8220;ItemCtrl&#8221;, we have defined items available for List , also we have defined two methods named add() and clear().</p>
<p><strong>What is Scope ?</strong></p>
<p>Scope is object in Angular which is used to bind data and other information between Controller and View. $scope defines that which data and which method can be accessed by controller. It is represented as <strong>$scope</strong>. If you see our javascript part of code, we have supplied $scope to controller method &#8220;ItemCtrl&#8221;.</p>
<p><strong>Model or directive &#8220;ng-model&#8221;:</strong></p>
<p>This is defined using directive &#8220;<strong>ng-model</strong>&#8220;. This is Engine Directive used to perform two way Binding of variable between View and Controller.</p>
<p>As shown in above code ; When we click on Checkbox, &#8220;ng-modal&#8221; directive will make sure that &#8220;done&#8221; attribute of item also set accordingly both side (Controller and View). In Same way When any value is added in Text Box, ng-model &#8220;itemToAdd&#8221; makes sure that it is available to Controller.</p>
<p><strong>How to iterate over List ? &#8220;ng-repeat&#8221; is savior.</strong></p>
<p>If you check our javascript part of code, you might be amazed that how list of items are iterated and added in UI? This magic is happen because of <strong>&#8220;ng-repeat&#8221;</strong> directive. One of the most used directives, it comes handy while iterating through list of items. In our case we iterated through items to create checkbox and &#8220;ng-modal&#8221; is used to make sure there is two way binding between View (HTML Components) and Controller.</p>
<p><strong>Last but not least, &#8220;ng-click&#8221;.</strong><br />
Used to invoke Javascript function defined in <strong>$Scope</strong> of Controller on click event. In Our case, we have defined two methods, add() and clear().</p>
<p>I hope this article will give you start with Javascript framework AngularJs. Feedback and suggestions are welcome !!!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/webtech/web/getting-started-with-angularjs/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3675</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-05-25 23:54:22 by W3 Total Cache
-->