javascript - Filter text without HTML tags in AngularJS -


i have simple angularjs app consumes json array of objects this:

$scope.faq = [  { id: 1, question: "what meaning of life?", answer: "42"},  { id: 2, question: "what <em>is<em> 1+1?", answer: "4"} ] 

in html have ng-repeat basic filter coming text input this

ng-repeat="qa in faq | filter:searchtext" 

the problem want search filter while ignoring html tags in json objects, searching phrase "what is" return both objects instead of first one. how change filter this?

write custom filter

in html:

ng-repeat="qa in faq | customfilter" 

in js:

angular.module('youmodule', []).   filter('customfilter', function() {     return function(input) {       var out;       //parse strings(find <tag> , exclude it) , push in out variable       return out;     }   }); 

upd can transmit in custom filter not input value (you can add parameter, such 'searchtext') html: ng-repeat="qa in faq | customfilter:searchstring"

js: return function(input, searchstring) {


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -