An AngularJS directive that puts emphasis on words within a string of text give one or more search terms. Simply include ng-emphasis in your HTML element and watch the magic happen.
bower install ng-emphasisangular.module('myApp', [
'ng-emphasis'
]);<style>
.ng-emphasis { font-weight: bold; }
</style><p ng-emphasis="'emphasis words'">Put emphasis on your words!</p><p ng-emphasis="emphasis words">Put <span class="ng-emphasis">emphasis</span> on your <span class="ng-emphasis">words</span>!</p>Put emphasis on your words!
angular.module('myApp')
.controller('MainCtrl', function() {
var vm = this;
vm.search = 'Sara Jo';
vm.users = [
'John',
'Sara',
'Mel',
'Jo'
];
});<span ng-repeat="user in users" ng-emphasis="search">{{ user }}</span> John Sara Mel Jo
See it in action | Demo
Configure the directive by injecting the configuration provider ngEmphasisConfigProvider.
angular.module('myApp')
.config(function(ngEmphasisConfigProvider) {
// Configurations go here
});Sets the CSS class to use in the directive template. If not configured, ngEmphasis will default to ng-emphasis as the CSS class name.
ngEmphasisConfigProvider.setCssClass('highlight');