<script src=”http://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js”></script>
<script src=”http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-sanitize.js”></script> <link rel=”stylesheet” href=”http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.css”/>

<div ng-app=”app”>
<div ng-controller=”ParentCtrl”>
<h2 style=”color:brown”>Filter Applied (logical OR)</h2>
<input type=”text” class=”search” placeholder=”Ask us anything |” ng-model=”searchText”>
<span style=”font-size:10px”>Search terms:’table cloth for'</span>
<div data-ng-repeat=”entry in data | myFilter:searchText:’AND'”>{{ entry }}</div>
</div></div>
<script>
angular.module(‘app’, [])
.filter(“myFilter”, function () {
return function (input, searchText, AND_OR) {
var returnArray = [],
// Split on single or multi space
splitext = searchText.toLowerCase().split(/\s+/),
// Build Regexp with Logical AND using “look ahead assertions”
regexp_and = “(?=.*” + splitext.join(“)(?=.*”) + “)”,
// Build Regexp with logicial OR
regexp_or = searchText.toLowerCase().replace(/\s+/g, “|”),
// Compile the regular expression
re = new RegExp((AND_OR == “AND”) ? regexp_and : regexp_or, “i”);

for (var x = 0; x < input.length; x++) {
if (re.test(input[x])) returnArray.push(input[x]);
}
// View what the 2 regular expression look like
console.log(input.length);
console.log(regexp_or);
console.log(regexp_and);
return returnArray;
}
});

function ParentCtrl($scope) {
$scope.data = [
“table cloth”,
“madhu cloth for table”,
“something else table”,
];
}
</script>

1412 Total Views 1 Views Today

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>