In did that for AngularJS v1.2+
HTML:
<span ng-bind-html="highlight(textToSearchThrough, searchText)"></span>
JS:
$scope.highlight = function(text, search) {
if (!search) {
return $sce.trustAsHtml(text);
}
return $sce.trustAsHtml(text.replace(new RegExp(search, 'gi'), '<span class="highlightedText">$&</span>'));
};
CSS:
.highlightedText {
background: yellow;
}
Related Contents:
- How to iterate over the keys and values with ng-repeat in AngularJS?
- passing 2 $index values within nested ng-repeat
- How to use ng-repeat for dictionaries in AngularJs?
- AngularJS For Loop with Numbers & Ranges
- Preserve line breaks in angularjs
- Using comma as list separator with AngularJS
- AngularJS – How can I reference the property name within an ng-Repeat
- How to make ng-repeat filter out duplicate results
- Angular ng-change delay
- Difficulty with ng-model, ng-repeat, and inputs
- Angular ng-repeat add bootstrap row every 3 or 4 cols
- Calculating sum of repeated elements in AngularJS ng-repeat
- AngularJS: ng-repeat list is not updated when a model element is spliced from the model array
- Show hidden div on ng-click within ng-repeat
- Directive isolate scope with ng-repeat scope in AngularJS
- angular ng-repeat skip an item if it matches expression
- Filtering an Angular 1.2 ng-repeat with “track by” by a boolean property
- How to remove elements/nodes from angular.js array
- AngularJS : Custom filters and ng-repeat
- Using ng-if as a switch inside ng-repeat?
- AngularJS sorting rows by table header
- AngularJS: list all form errors
- Do bindings nested inside of a lazy one-time ng-repeat binding bind just once?
- AngularJS: ng-repeat track by $index inside nested loops
- ng-repeat filter on boolean
- ng-repeat: access key and value for each object in array of objects
- Using ng-repeat and ng-class on rows inside a table
- AngularJS – How to structure a custom filter with ng-repeat to return items conditionally
- Angular ng-repeat conditional wrap items in element (group items in ng-repeat)
- How to highlight a selected row in ngRepeat?
- ng-repeat specify a starting index
- $first in ngRepeat
- AngularJS – Model not updating on selection of radio button generated by ng-repeat
- How to use “ng-repeat” within template of a directive in Angular JS?
- How to sort object data source in ng-repeat in AngularJS?
- orderBy two fields (one in reverse)
- angularjs text area character counter
- How to obtain previous item in ng-repeat?
- is there a post render callback for Angular JS directive?
- fatal: in unpopulated submodule
- No ‘Access-Control-Allow-Origin’ header is present on the requested resource- AngularJS
- Why are AngularJS $http success/error methods deprecated? Removed from v1.6?
- How to reload / refresh model data from the server programmatically?
- AngularJS. Convert tag value (Unix time to human-readable time)
- $watch not firing on data change
- Reusable components in AngularJS
- ngRepeat Filter by deep property
- Protractor waiting for element to be in DOM
- How to interact with back-end after successful auth with OAuth on front-end?
- How to see what states are configured in AngularJS / UI-Router?