javascript - Formatting Angular JS/Bootstrap Tabs -
javascript/html/angular newbie here. run problem has me stumped, can't find online me.
i've created small application uses bootstrap tabs. here's code responsible creating tabs:
<tabset class="tab-container"> <tab ng-repeat="tab in tabs" active="tab.active"> <!-- tab highlight directive --> <tab-heading> <span>{{tab.title}}</span> <i class="glyphicon glyphicon-remove" ng-click="removetab($event, $index)"></i> <!-- tab close button --> </tab-heading> {{tab.content}} </tab> <button class="btn btn-default" ng-click="addtab()"></button> </tabset> i want add highlights words in tabs (for example, if tab contents "the lazy fox", want highlight fox in yellow). when try adding html tags tab.content, tabs don't parse html tags , displays them normal text.
thanks help!
i see, using angularui (which great :) ). here filter solve problem:
add javascript project (you can reuse everywhere):
and
angular.module('highlightdemo', ['ngsanitize']); and following filter:
app.filter('highlight', function () { return function (text, search, casesensitive) { if (text && (search || angular.isnumber(search))) { text = text.tostring(); search = search.tostring(); if (casesensitive) { return text.split(search).join('<span class="ui-match">' + search + '</span>'); } else { return text.replace(new regexp(search, 'gi'), '<span class="ui-match">$&</span>'); } } else { return text; } }; }); setup highlight options (in controller):
$scope.hightlightsearchkeyword = 'the fox';
and able use filter everywhere.
<span ng-bind-html="tab.content | highlight:hightlightsearchkeyword"></span> make sure add add a css style span.ui-match example
.ui-match { background: yellow; }
Comments
Post a Comment