简体   繁体   English

Add html elements and json list inside angular typescript class

[英]Add html elements and json list inside angular typescript class

I have this code.我有这个代码。

  this._notificationService.showInfoMessage
        (
          'The list below cannot be reached'
            + `'<ul>
             <li> ${this.tagList
            .map(i => i.tag)
            .join(',')} </li>
            </ul>'`
        );

It does not work这没用

I want add html list for this tag list and show list items one by one as a list with bullets.我想为此标签列表添加 html 列表,并将列表项一一显示为带有项目符号的列表。 I have tried many ways.我尝试了很多方法。

I made it using browser inspect view I want to get as below one我使用浏览器检查视图制作它,我想得到如下一个

在此处输入图像描述

please suggest best way for this请为此建议最好的方法

Why it doesn't work?为什么它不起作用? Just check what says the official Angular documentation.只需查看官方 Angular 文档的内容即可。

Angular recognizes the value as unsafe and automatically sanitizes it, which removes the script element but keeps safe content such as the element. Angular 将该值识别为不安全并自动对其进行清理,从而删除脚本元素但保留元素等安全内容。

https://angular.io/guide/security#sanitization-example https://angular.io/guide/security#sanitization-example

That is how it's works!这就是它的工作原理!

But still, you have many options to achieve your goal.但是,您仍然有很多选择来实现您的目标。

Since you have a list/array of tags you could just iterate over them in the template and using string interpolation.由于您有一个标签列表/数组,您可以在模板中迭代它们并使用字符串插值。

 <ul>
  <li *ngFor="let tag of tags">{{tag}}</li>
 </ul>

Text interpolation: https://angular.io/guide/interpolation文字插值: https://angular.io/guide/interpolation

PS Please, share with us what your service/component looks like. PS 请与我们分享您的服务/组件的外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM