tommyd456
tommyd456

Reputation: 10683

Replacing text using a filter

Can't get my filter to work. I'm trying to remove the <br> tags and replace them with ""

So far I have this in my view:

<span ng-bind-html="description | stripbreaks"></span>

and my filter is:

.filter('stripbreaks', function(text){
    return text.replace(/<br>/g, '');
});

but I'm getting the following error: Unknown provider: textProvider <- text <- stripbreaksFilter

This is the first time I've used my own filter so anything I'm doing wrong?

Upvotes: 4

Views: 313

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136154

You had wrong syntax. Basically the outer function of filter stands for injecting dependency, and then the inner function gets called on each digest cycle to updated view.

The Unknown provider: textProvider <- text <- stripbreaksFilter error occured because you were put text inside the outer function

Filter

.filter('stripbreaks', function(){
   return function(text){
      return text.replace(/<br>/g, '');
   }
});

Upvotes: 5

Related Questions