alibt
System Dependency Auditor
LEVEL 1
200 XP
In this tutorial we will create a Filter JSON Data In AngularJS. This code will filter the json data when the user enter a keyword in the form. The code itself use an AngularJS directives that has a several built-functionalities that can filter a data in the table by binding the textbox with ng-model and adding a filter parameter in the ng-repeat. This is a free source code you can modify it and use it on your working programs.
We will be using AngularJS as a JavaScript-based open-source front-end web application framework . 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.
Getting started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Lastly, you will need to download the AngularJS here's the link https://angularjs.org/.
Note: This code will only work if run in a local server.
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 this as index.html.
Creating the Main Function
This code contains the main function of the application. This code will filter the JSON data from a JSON file. To that just kindly copy and write these block of codes inside the text editor, then save it as shown below.
member.json
[
{"firstname": "John", "lastname": "Smith", "address": "New York"},
{"firstname": "Claire", "lastname": "Temple", "address": "Racoon City"}
]
script.js
Note: Save this file inside the js directory as script.js to make the program work.
There you have it we successfully created a Filter JSON Data In 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!!
Download
We will be using AngularJS as a JavaScript-based open-source front-end web application framework . 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.
Getting started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Lastly, you will need to download the AngularJS here's the link https://angularjs.org/.
Note: This code will only work if run in a local server.
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 this 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"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
JavaScript - Filter JSON Data In AngularJS</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-8"
>
- <div
class
=
"form-inline pull-right"
>
- <input
type
=
"text"
class
=
"form-control"
ng-model=
"filter"
placeholder=
"Search here..."
/
>
- </
div
>
- <br
/
><br
/
>
- <table
class
=
"table table-bordered"
>
- <thead
class
=
"alert-info"
>
- <tr
>
- <th
>
Firstname</
th
>
- <th
>
Lastname</
th
>
- <th
>
Address</
th
>
- </
tr
>
- </
thead
>
- <tbody
>
- <tr
ng-repeat=
"member in members | filter: filter"
>
- <td
>
{{member.firstname}}</
td
>
- <td
>
{{member.lastname}}</
td
>
- <td
>
{{member.address}}</
td
>
- </
tr
>
- </
tbody
>
- </
table
>
- </
div
>
- </
div
>
- <script
src
=
"js/angular.js"
></
script
>
- <script
src
=
"js/script.js"
></
script
>
- </
body
>
- </
html
>
Creating the Main Function
This code contains the main function of the application. This code will filter the JSON data from a JSON file. To that just kindly copy and write these block of codes inside the text editor, then save it as shown below.
member.json
[
{"firstname": "John", "lastname": "Smith", "address": "New York"},
{"firstname": "Claire", "lastname": "Temple", "address": "Racoon City"}
]
script.js
Note: Save this file inside the js directory as script.js to make the program work.
- var
app =
angular.module
(
'myModule'
,
[
]
)
- .controller
(
'myController'
,
function
(
$scope,
$http)
{
- $http.get
(
'member.json'
)
.then
(
function
(
response)
{
- $scope.members
=
response.data
;
- }
)
;
- }
)
;
There you have it we successfully created a Filter JSON Data In 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!!
Download
You must upgrade your account or reply in the thread to view the hidden content.