I currently have a code that allows me to filter a JSON object by both the name and the title. I have an array with a few words, I would like to make this same filter but without hiding the words, just mark them based on my array.
$scope.arrayFilter=["bad,bill,mikle,awesome,mosa"];
Is it possible to perform this filter by default when I start my application ?. Thank you very much.
https://jsfiddle.net/ryvu49jt/
$scope.data = [{
title: "Bad",
name: 'bill'
}, {
title: "Good",
name: 'Goe'
}, {
title: "Great",
name: 'Brad'
}, {
title: "Cool",
name: 'yan'
}, {
title: "Excellent",
name: 'mikle'
}, {
title: "Awesome",
name: 'mosa'
}, {
title: "Horrible",
name: 'morteza'
} ]
}).filter('highlight', function($sce) {
return function(text, phrase) {
if (phrase) text = text.replace(new RegExp('(' + phrase + ')', 'gi'),
'<span class="highlighted">$1</span>')
return $sce.trustAsHtml(text)
}
})
Currently if I type a word in a text field, it is filtered by both the name and the title of my JSON object. Are marked but disappear. I just want them to be marked, not disappear.
thanks a lot!