After successfully cleaning up an external JSON URL feed by removing unnecessary special characters through a filter in my AngularJS code, I am now faced with the challenge of filtering out specific items from an ng-repeat based on a certain string.
angularJS.filter('removeChar', function(){
return function(text) {
text = text.replace(/\[[^\]]+\]/g, ''); // Characters inside Brackets
return text.replace(/\;.*/, ''); // Characters after Colon
};
});
<span ng-bind-html-unsafe="item | removeChar">{{item}}</span>
For instance, I want to exclude items containing the words 'Red' or 'Green' from being displayed in the ng-repeat. Here is how I envision using the filter:
<div ng-repeat="item in items | removeItem">{{item['flowers']}}</div>
The following items are considered:
<div>Blue Roses</div>
<div>Red Roses</div>
<div>Orand and Green Roses</div>
<div>Yellow Roses</div>
<div>Red and Green Roses</div>
With the filter applied, only these items will be displayed:
<div>Blue Roses</div>
<div>Yellow Roses</div>
I would appreciate it greatly if someone could provide me with a helpful example.
Thank you! Roc.