JavaScript - Filtering Entry Using AngularJS
Submitted by razormist on Monday, December 30, 2019 - 14:31.
In this tutorial we will create a Filtering Entry using AngularJS. This code will filter entries of data inside the html table when user submit the input form. The code use angular directives to filter an entry data by binding the textbox in ng-model and adding the filter function in the ng-repeat with the same value as the model. This a user-friendly program feel free to modify and use it to your system.
We will be using AngularJS as a framework which has additional custom HTML attributes embedded into it. It can interprets those attributes as directives to bind inputted parts of the page to a model that represent as a standard JavaScript variables.
There you have it we successfully created a Filtering Entry using AngularJS. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Getting started:
First you will need to download & install the AngularJS here's the link https://angularjs.org/. And this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.Creating the Main Interface
This code contains the interface of the application. This code will render application and display the form. To do that just kindly write these block of code inside the text editor and save it as index.html.- <!DOCTYPE html>
- <html lang="en" ng-app="myModule">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
- </head>
- <body ng-controller="myController">
- <nav class="navbar navbar-default">
- <div class="containet-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-4">
- <form>
- <div class="form-group">
- <input type="text" class="form-control" ng-model="newMember.firstname"/>
- </div>
- <div class="form-group">
- <input type="text" class="form-control" ng-model="newMember.lastname"/>
- </div>
- <div class="form-group">
- <input type="text" class="form-control" ng-model="newMember.address"/>
- </div>
- </form>
- </div>
- <div class="col-md-8">
- <div class="form-inline">
- <input type="text" class="form-control" ng-model="searchBox"/>
- </div>
- <br />
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- </tr>
- </thead>
- <tbody>
- <tr ng-repeat="member in members|filter: search">
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the main function of the application. This code will filter entries when the user submit the input form. To that just kindly copy and write these block of codes inside the text editor, then save it inside the js directory as script.js.- var app = angular.module("myModule", [])
- .controller("myController", function($scope){
- $scope.newMember = {};
- $scope.clickedMembers = [];
- $scope.members = [];
- $scope.saveMember = function(){
- $scope.members.push($scope.newMember);
- $scope.newMember = {};
- };
- });
Add new comment
- 66 views