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:

  1. add javascript project (you can reuse everywhere):

    https://code.angularjs.org/1.3.10/angular-sanitize.js

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;         }     }; }); 
  1. setup highlight options (in controller):

    $scope.hightlightsearchkeyword = 'the fox';

and able use filter everywhere.

<span ng-bind-html="tab.content | highlight:hightlightsearchkeyword"></span> 
  1. make sure add add a css style span.ui-match example

    .ui-match { background: yellow; }


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -