Skip to content Skip to sidebar Skip to footer

How To Search And Highlight In Angular Js?

I have a div in which I have some contend in that .I need to search text from that div and highlight the word (using css class).using next it search next word occurrence and previo

Solution 1:

you can use your old search algorithm, as an example: http://plnkr.co/edit/As9iyCVtMMNH7lyprJA9?p=preview

what is added is

<buttonng-click="searchFirst(searchtext)">FirstText</button>

example search, forward only (prev implementation not AngularJS related)(see link for running example):

Try searching "sear"... have tested on that word only... =)

app.controller("contr",function($scope){

  var searcher = new Searcher();

  var div = angular.element(document.getElementById('content'));

  $scope.searchFirst=function(str){
    searcher.setOffset(0);
    searcher.setContent(div.text());
    div.html(searcher.search(str));
  }

  $scope.nextSearch=function(){
    div.html(searcher.search());
  }

   $scope.preSearch=function(){
     // you implement
  }
});

Post a Comment for "How To Search And Highlight In Angular Js?"