4

I have a situation where i need to display images if the chat messages come with image link,currently i am displaying just as image link.

One solution i thought that i will check for lastIndexOf('.') and get the extension and match it within ng-if,but i feel it will not be neat solution. Hence i am looking for any library or angular built in module which does it for me just like:

linkify(Linkify is a JavaScript plugin for finding links in plain-text and converting them to HTML tags)

Pratswinz
  • 1,476
  • 11
  • 24

1 Answers1

-1
imgify(text) {
    const regexp = /\b(https?:\/\/\S+(?:png|jpe?g|gif)\S*)\b/ig;
    const replace = "<br><img src='$1'>";
    return text.replace(regexp, replace);
}
Alexey Sh.
  • 1,734
  • 2
  • 22
  • 34