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
function Person(){
this.age = 0;
this.kill = function() {window.clearInterval(this.interval);};
this.interval = setInterval(() => {
this.age++; // this refers to the person object
}, 1000);
}
正如您可以看到回复一样,完整的Google会出现在页面上,而不是超链接,只是来自回复的文本,我只想显示Google以及超链接。
EDITS
HTML
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="www.google.com">Google</a>
我也尝试过这个
<p *ngIf="value && string">
{{string.getString(value)}}
</p>
它在网页上打印了相同的文字,而且它没有获得任何数据
String是我使用的服务,而getString()是其中的方法。
字符串服务
<p *ngIf="value && string">
[innerHtml]="string.getString(value)"
</p>
来自api的回复:
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
}
}
到目前为止我所做的是我去了:How to make clickable URL's in JSON response from REST using AngularJS?
了解Autolinker,但这不是我要找的东西。请以角度形式帮助实现这一目标。如果有任何问题我在这里解释。感谢
解决
感谢所有给我们时间然后帮助我的人,但特别感谢@PierreDuc PierreDuc提供了神奇的帮助。所以,我必须做的事情并没有正确地进行。
{
"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."
}
}
它有效。再次感谢!!