python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions