Search code examples
htmlangularinnerhtml

Is there any way to open link in anew tab from inner html (angular 6)


I have a span tag with inner html like this

In my html :

<span [innerHTML]="description"></span>

and in my ts:

description = "some random text  https://stackoverflow.com/ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"

displaying it like this

It displays the link but when I click on that link it is opening in the same tab but I want it be opened in a new tab.

Is there any way to do this?


Solution

  • In this case that you are using innerHtml property binding you can place a html link in your description text with target="_blank" to open the link in a new tab:

    description =
        'some random text <a href="https://stackoverflow.com" target="_blank">https://stackoverflow.com/</a> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s';