I have an api which gives me a string and I have to show the response on my HTML file, but after a lot of research I'm unable to figure out what to do.
The problem is that in the response the string has some <a>XYZ</a>
tag in it and I need to show XYZ as the hyperlink. Right now the data is coming like
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="www.google.com">Google</a>
As you can see the response, the full Google is coming on the page without the hyperlink simply the text from the response where I want to display the Google only and also with the hyperlink.
EDITS
HTML
<p *ngIf="value && string">
{{string.getString(value)}}
</p>
And I have tried doing with the this also
<p *ngIf="value && string">
[innerHtml]="string.getString(value)"
</p>
It printed the same text in the webpage and moreover it didn't get any data
String is a service which I'm using to and getString() is method in it.
String Service
export class StringService {
string : any
constructor(private http : HttpClient) {
this.http.get("/strings").subscribe(data => {
this.strings = data['strings']
})
}
getString(key : string){
if(key == "WEB_ABOUT_US")
return this.strings.WEB_ABOUT_US;
else if(key == "WEB_CLASSES_TITLE")
return this.strings.WEB_CLASSES_TITLE;
return null
}
}
The response from the api :
{
"strings": {
"WEB_ABOUT_US": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href=\"www.google.co.in\">Google</a> Sed tellus justo, euismod non sodales eget, faucibus accumsan odio. Nunc quis venenatis dui. Vestibulum ut nunc nec augue imperdiet lobortis vitae eget ex. Curabitur ut elit et lacus euismod fringilla. Vivamus interdum massa quis sollicitudin ornare. Sed sed urna id diam sollicitudin tempus vel in elit. Duis malesuada massa et purus imperdiet, ac varius nulla volutpat. In feugiat quis sapien et tempus."
}
}
What I have done so far is I went to this : How to make clickable URL's in JSON response from REST using AngularJS?
Read about Autolinker but it is not the thing which I'm looking for. Kindly help to achieve this in angular form. If any question comes up I'm here to explain. Thanks
SOLVED
Thanks to all of you who gave their time and then helped me out but special thanks to @PierreDuc PierreDuc for the help which did the magic. So the thing which I had to do I was not working on it correctly.
<p [innerHTML]="string.getString('WEB_ABOUT_US')"></p>
and it worked. Thanks Again!!