Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight searched text in result #95

Open
Disane87 opened this issue Nov 14, 2016 · 1 comment
Open

Highlight searched text in result #95

Disane87 opened this issue Nov 14, 2016 · 1 comment

Comments

@Disane87
Copy link

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

@asiddeen
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants