• We just launched and are currently in beta. Join us as we build and grow the community.

Search Filter with AngularJS

kmfkmsfk

Senior Member
K Rep
0
0
0
Rep
0
K Vouches
0
0
0
Vouches
0
Posts
53
Likes
12
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this tutorial, we are going to create another Search Filter with AngularJS function. This function has always been difficult in terms of looking up for data. With the use of AngularJS, this will be easy for us to create this kind of function.

Creating Markup

  • Create TextBox for search.
  • Preparing for the list of country names.

1_145.png


Kindly copy and paste this HTML source code to your BODY tag of your page.

  1. <div

    class

    =

    "container"

    >
  2. <input

    type

    =

    "text"

    ng-model=

    "filter_Country"

    placeholder=

    "Search . . . . . "

    autofocus=

    "autofocus"

    /

    >
  3. <img

    src

    =

    "img/search.png"

    alt

    =

    "S"

    class

    =

    "search-icon"

    title

    =

    "search"

    >

  4. <div

    class

    =

    "holder-country"

    >
  5. <div

    class

    =

    "header-country center"

    >
  6. Country List
  7. </

    div

    >
  8. <div

    class

    =

    "list-country-scrollbar"

    >
  9. <div

    class

    =

    "list-country"

    ng-repeat=

    "country in countrylist | filter: filter_Country"

    >

    {{country.name}}</

    div

    >
  10. </

    div

    >
  11. </

    div

    >
  12. </

    div

    >

Preparing Script

  • Fetch all country list name using the get method.
  • Bind the array for a country name to view.

Kindly copy and paste this script before the end of your BODY tag of your page.

  1. <

    script src=

    "js/angular.js"

    ></

    script>
  2. <

    script src=

    "js/jQuery.js"

    ></

    script>
  3. <

    script src=

    "js/slimscroll.js"

    ></

    script>
  4. <

    script>
  5. var

    app =

    angular.module

    (

    'search_Country'

    ,

    [

    ]

    )

    ;

  6. app.controller

    (

    'Country_Controller'

    ,

    function

    (

    $scope,

    $http)

    {
  7. $http.get

    (

    'js/country.json'

    )

    .then

    (

    function

    (

    list)

    {
  8. $scope.countrylist

    =

    list.data

    ;
  9. jQuery(

    '.list-country-scrollbar'

    )

    .slimScroll

    (

    {
  10. height:

    '250px'
  11. }

    )

    ;
  12. }

    )

    ;
  13. }

    )

    ;
  14. </

    script>

List of Country Names in JSON
  1. [
  2. {

    "name"

    :

    "Virgin Islands, British"

    }

    ,
  3. {

    "name"

    :

    "Virgin Islands, U.S."

    }

    ,
  4. {

    "name"

    :

    "Wallis and Futuna"

    }

    ,
  5. {

    "name"

    :

    "Western Sahara"

    }

    ,
  6. {

    "name"

    :

    "Yemen"

    }

    ,
  7. {

    "name"

    :

    "Zambia"

    }

    ,
  8. {

    "name"

    :

    "Zimbabwe"

    }
  9. ]

Result

2_65.png


And, that's it. This is the steps on how to create Search Filter with AngularJS.

Kindly click the "Download Code" button below for full source code. Thank you very much.

Hope that this tutorial will help you a lot.

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

329,392

329,400

Top