ionic-filter-bar icon indicating copy to clipboard operation
ionic-filter-bar copied to clipboard

Highlight searched text in result

Open Disane87 opened this issue 7 years ago • 1 comments

Is it possible to highlight the searched text in the results?

Disane87 avatar Nov 14 '16 14:11 Disane87

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); }

asiddeen avatar Jun 29 '17 12:06 asiddeen