Replace in Angularjs

Asked

Viewed 462 times

1

<br><br>This powerful creation - forged in the image of a gargoyle - the kept<br><br> safe on his journeys, allowing him perform their important work without fear of retaliation from those hostile to their homeland.<br><br> That is, until the wrath of Noxian High Command with its sentinels.<br><br>

Using {{content.lore}} in my html I display the above text. When I try to use content.lore.replace("<br>", "") the words <br> are not replaced. How can I replace them?

  • Post a snippet of the javascript code you have, if possible.

  • I found the solution in the OR, I put it here or delete the question?

  • Answer your own question, it may be other users' question (:

1 answer

2


One of the ways is by using a filter that converts HTML to text:

app.filter('htmlToText', function(){
  return function(html){        
     return angular.element('<div>').append(html || '').text();
  };
});

In view:

{{content.lore | htmlToText}}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.