I am working on creating a filter that can filter by both short names and full names.
So far, I have successfully implemented filtering by full name using AngularJS:
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
'Indian Overseas Bank',
'Housing Development Finance Corporation',
'Industrial Credit and Investment Corporation of India',
'Indian Bank',
'City Bank',
'City Union Bank',
'Kotak Mahindra Bank',
'Tamilnadu Mercantile Bank ',
'State Bank Of India'
];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<div ng-app="myApp" ng-controller="namesCtrl">
<p>Type a letter in the input field:</p>
<p><input type="text" ng-model="test"></p>
<ul>
<li ng-repeat="x in names | filter:test">
{{ x }}
</li>
</ul>
</div>
Now, my challenge is to figure out how to filter by short names like IOB, HDFC, SBI
.
The desired outcome would look like this:
Filter word : Expected result
IOB : Indian Overseas Bank
HDFC : Housing Development Finance Corporation
SBI : State Bank of India
ICICI : Industrial Credit and Investment Corporation of India'
Please note: All banks mentioned are Indian banks. When filtering by SBI and ICICI
, common words such as of, and
should not affect the results.
Additionally, if I enter a generic term like
India
, I expect the same filtering behavior as seen in the existing code snippet. How can I achieve this?