Text filtering while using selection box in angularjs

Text filtering while using selection box in angularjs

Table of context (click for live plunker demo)

1. HTML Template Binding code sample
2. AngularJs code sample
3. Full example code

HTML code sample
?
01
02
03
04
05
06
07
08
09
10
<div ng-app="myApp">
  <div ng-controller="filteringController">
    <select ng-model="inputText">
      <option ng-repeat="cont in countries">{{cont.name}}</option>
    </select>
    <ul>
      <li ng-repeat="cont in countries | filter:inputText">Ids of {{cont.name}} is {{cont.Id}}</li>
    </ul>
  </div>
</div>
<div ng-app="myApp">
  <div ng-controller="filteringController">
    <select ng-model="inputText">
      <option ng-repeat="cont in countries">{{cont.name}}</option>
    </select>
    <ul>
      <li ng-repeat="cont in countries | filter:inputText">Ids of {{cont.name}} is {{cont.Id}}</li>
    </ul>
  </div>
</div>
AngularJs code sample
?
01
02
03
04
05
06
07
08
09
10
var app = angular.module("myApp", []);
app.controller('filteringController', function($scope) {
  $scope.countries = [{
    name: "India",
    Id: "1"
  }, {
    name: "Nepal",
    Id: '2'
  }];
});
var app = angular.module("myApp", []);
app.controller('filteringController', function($scope) {
  $scope.countries = [{
    name: "India",
    Id: "1"
  }, {
    name: "Nepal",
    Id: '2'
  }];
});
Full Example code
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8 />
  <title>filtering country while using selection box in angularjs</title>
  <script>
    var app = angular.module("myApp", []);
    app.controller('filteringController', function($scope) {
      $scope.countries = [{
        name: "India",
        Id: "1"
      }, {
        name: "Nepal",
        Id: '2'
      }];
    });
  </script>
</head>
<body ng-app="myApp">
  <div ng-controller="filteringController">
    <select ng-model="inputText">
      <option ng-repeat="cont in countries">{{cont.name}}</option>
    </select>
    <ul>
      <li ng-repeat="cont in countries | filter:inputText">Ids of {{cont.name}} is {{cont.Id}}</li>
    </ul>
  </div>
</body>
</html>
<!DOCTYPE html>
<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
  <meta charset=utf-8 />
  <title>filtering country while using selection box in angularjs</title>
  <script>
    var app = angular.module("myApp", []);
    app.controller('filteringController', function($scope) {
      $scope.countries = [{
        name: "India",
        Id: "1"
      }, {
        name: "Nepal",
        Id: '2'
      }];
    });
  </script>
</head>

<body ng-app="myApp">
  <div ng-controller="filteringController">
    <select ng-model="inputText">
      <option ng-repeat="cont in countries">{{cont.name}}</option>
    </select>
    <ul>
      <li ng-repeat="cont in countries | filter:inputText">Ids of {{cont.name}} is {{cont.Id}}</li>
    </ul>
  </div>
</body>

</html>
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.