Saturday, November 4, 2017

Pagination in the angular js

Today we are going to see how to add the pagination to the table in angular js application there are many different ways to do it but I do it using the pagination library on GitHub. GitHub is one of the best platforms for the developers there are lots of libraries created by the developers like us we can use them instead of creating out on our own using the existing thing is much better and time-saving
The link to the library is here dirpagination
Lets start
<html data-ng-app="app">

<head>
    <script src="…\angular.min.js"></script>
    <script src="…\dirPagination.js"></script>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
        crossorigin="anonymous"/>

    <script >
        var app = angular.module('app', ['angularUtils.directives.dirPagination']);
        app.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) {

            $scope.items = [

                {
                    name: "ram",
                    age: "23"
                },
                {
                    name: "vijay",
                    age: "25"

                },
                {
                    name: "sham",
                    age: "24"

                },
                {
                    name: "raju",
                    age: "59"

                },
                {
                    name: "babu j",
                    age: "20"

                },
                {
                    name: "kml r",
                    age: "12"

                }
            ]

        }]);
    </script>

   
</head>

<body>
    <h1 class="page-header" style="text-align:center">Basic Angular App</h1>
    <div class="container" data-ng-controller="MyCtrl">
      <div class="container">
        <div class="row">
            <div class="col-sm-2">Search</div>
            <div class="col-sm-2">
                <input type="text" class="form-control input-sm" data-ng-model="txtSearch">
            </div>
        </div>
    </div>
    <hr>
   
    <div class="container">
            <table class="table table-responsive table-hover table-bordered">
                <tr>
                    <th>Name</th>
                    <th>Age</th>
                </tr>
                <tr dir-paginate="item in items | itemsPerPage: 5 | filter : txtSearch">
                    <td>{{item.name}}</td>
                    <td>{{item.age}}</td>
                </tr>
            </table>
            <dir-pagination-controls></dir-pagination-controls>
          
        </div>
    </div>
</body>

</html>

In the above example we have used the dirPagination.js for the pagination but we need to replace the data-ng-repeat which we use to bind the data to the table to dir-paginate we can also see that we have used the itemsPerPage: 5 and also there are many different options in that directive ex-

<dir-pagination-controls
[max-size=""]
[direction-links=""]
[boundary-links=""]
[on-page-change=""]
[pagination-id=""]
[template-url=""]
[auto-hide=""]>
</dir-pagination-controls>

In that way, we can add the pagination in angular application for better understanding of the directive go through the documentation 

Search in angular js

Today we are going to see how to add the search functionality in the angular js. To add the search functionality in angular we are making use of the filters in angular js.There are also different types of filters available in angular. please do check Angular Docs what are the other different types of filters available for angular js and how we can use it in our application. So let’s start

<html data-ng-app="app">
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js" />

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
        crossorigin="anonymous">
    <script>
        var app = angular.module('app', []);
        app.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) {

            $scope.items = [

                {
                    name: "ram",
                    age: "23"
                },
                {
                    name: "vijay",
                    age: "25"

                },
                {
                    name: "sham",
                    age: "24"

                },
                {
                    name: "raju",
                    age: "59"

                },
                {
                    name: "babu j",
                    age: "20"

                },
                {
                    name: "kml r",
                    age: "12"

                }
            ]

        }]);
    </script>
</head>

<body>
    <h1 class="page-header" style="text-align:center">Basic Angular App</h1>
    <div class="container" data-ng-controller="MyCtrl">
        <div>
            <div class="col-sm-2">Search</div>
            <div class="col-sm-2">
                <input type="text" class="form-control input-sm" data-ng-model="txtSearch">
            </div>
        </div>
        <hr>
        <table class="table table-responsive table-hover">
            <tr>
                <th>Name</th>
                <th>Age</th>
            </tr>
            <tr data-ng-repeat="item in items | filter : txtSearch">
                <td>{{item.name}}</td>
                <td>{{item.age}}</td>
            </tr>
        </table>

    </div>
</body>
</html>


In the above example we have used the angular js directive known as data-ng-repeat which works same like the foreach loop in the above we have also created the controller named  MyCtrl  and inside the controller we have created the array called as items [] which stores the JSON data which we have used to bind the table In the data-ng-repeat  you can see that we have made use of the filter keyword that is nothing but the angular js filter in that we are just passing the model name of the search text box and it will automatically search the results based on the input entered in the text box so by that way we can easily create the search functionality in the angular js.

Wednesday, November 1, 2017

Angular Js (Basic App)

Today we are going to see how to create a basic angular app from scratch.For creating an angular js app we can use any of the code editors there are lots of code editors available online which are available for free or you can call it open source I’m using Visual Studio Code that’s one of my Favourite do tell me in the comments below which is yours favourite.

First add the Angular Js library from any of the CDN or angularjs.org site.
Links are below
Or

<html data-ng-app="">

<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js" />
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"integrity="sha384BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4"crossorigin="anonymous">

</head>

<body>

    <h1 class="page-header" style="text-align:center">Basic Angular App</h1>

    <div class="container">
        <div class="row">
            <div class="col-sm-2">
                <span>Enter Message</span>
            </div>
            <div class="col-sm-2">

                <input type="text" data-ng-model="message">
            </div>

        </div>

        <h1>{{message}}</h1>

    </div>
</body>

</html>

In the above example we have created a basic angular app which takes the input from the user and displays. Here the data-ng-app= ” ” is to indicate the browser that this is a angular js application in many other cases you might have already seen the code without the prefix data- added the reason is that some browser did not recognize the angular application so to indicate we need to specify that but now a days most of the latest browsers identifies that it is an angular js application then next the part data-ng-model is like the id which we give for the input field and {{message}}  the  curly braces {{}} are called expressions which we have used to display the data we inserted. I have also given the link below for the angular js Angular Docs   please go through the documentation for more clear picture.

Git Commands

Git Version   To check the git version Git -v       Git Clone To clone the repository, use the following command: Git clone [u...