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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
http://www.code-sample.com
http://www.code-sample.xyz

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.