ionic-filter-bar
ionic-filter-bar copied to clipboard
Highlight searched text in result
Is it possible to highlight the searched text in the results?
Hello @Disane87
you can use directive to achieve it;
directive:
.filter('highlight', function($sce) { return function(text, phrase) { if (phrase) text = text.replace(new RegExp('('+phrase+')', 'gi'), '<span class="highlighted">$1</span>'); return $sce.trustAsHtml(text); }; })
controller:
$rootScope.cText = ''; var filterBarInstance; $scope.showFilterBar = function () { filterBarInstance = $ionicFilterBar.show({ items: $scope.fcontactsList, update: function (filteredItems, filterText) { $scope.fcontactsList = filteredItems; if (filterText) { console.log(filterText); $rootScope.cText = filterText; } } }); };
html:
<h2 ng-bind-html="client.accountName | highlight:cText" style="font-weight: 500">{{client.accountName}}</h2>
css:
.highlighted { color: rgba(216, 69, 59, 0.64); }