JavaScript - Simple Search Box Using AngularJs
Submitted by razormist on Wednesday, January 23, 2019 - 15:54.
In this tutorial we will create a Simple Search Box Using AngularJS. AngularJS is a structural framework for dynamic web apps. It is a kind of template that extends HTML to a new level of coding techniques. It is mostly used by other well known site for creating a template.
There you have it we successfully created a Simple Search Box 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="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="form-inline">
- <input type="text" class="form-control" ng-model="search" placeholder="Search here..."/>
- </div>
- <br />
- <table class="table table-bordered">
- <thead class="alert-success">
- <tr>
- </tr>
- </thead>
- <tbody style="background-color:#fff;">
- <tr ng-repeat="student in students | orderBy: 'lastname' | filter: search">
- </tr>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Creating the Script
This code contains the main function of the application. This code will display data and will filter the content base on the input text box. 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){
- var students = [
- {firstname: "John", lastname: "Smith", gender: "Male" , address: "Japan"},
- {firstname: "San", lastname: "Juan", gender: "Male" , address: "China"},
- {firstname: "Kim", lastname: "Fang", gender: "Female" , address: "USA"},
- {firstname: "Stan", lastname: "Lou", gender: "Male" , address: "New York"},
- {firstname: "Mike", lastname: "Roger", gender: "Male" , address: "Germany"},
- {firstname: "Joan", lastname: "Lia", gender: "Female" , address: "France"},
- {firstname: "Mikaela", lastname: "Clars", gender: "Female" , address: "Spain"},
- {firstname: "Robert", lastname: "Stark", gender: "Male" , address: "Africa"}
- ];
- $scope.students = students;
- });
Add new comment
- 272 views