简体   繁体   English

如何在 angular 中以正确的格式显示富文本

[英]How to display rich Text in it's right format in angular

I am fetching some data from a strapi endpoint and displaying it to user.我正在从 strapi 端点获取一些数据并将其显示给用户。 The data is a paragraph content.数据是一段内容。 It is in the rich text format which means that when I display it on a page using a p tag, It displays it with all the rich text formats.它采用富文本格式,这意味着当我使用p标签在页面上显示它时,它会以所有富文本格式显示。 ie "**" as bold and so on.即“**”为粗体等。 How can I diplay this as it should be?我怎样才能按原样显示它?

In the.ts file, `在.ts文件中,`

//lets assume that datatservice is my service to get the data from strapi endpoint
import {dataservice} from './service'
//content will store the content being fetched
content:any;

constructor( private data:dataservice ){}

ngOnInit(){
this.getData();
}

getData():void{
 this.dataservice.getContent().subscribe((res)=>{
    this.content=res.attributes.content;
    //lets assume that content of the data being fetched is " **Hello** my name is Kelvin."
})
}

and I am displaying it in the html as我在 html 中显示为

<div>
<p>{{content}}</p>
</div>

this is what is shown这就是显示的内容

**Hello** my name is kelvin

but need it to be shown like this但需要这样显示

**Hello** my name is kelvin. (where the Hello is bold)

You need to either write your own component or find one on the inte.net (and use it via npm) that can format the input like that.您需要编写自己的组件或在 inte.net 上找到一个可以像这样格式化输入的组件(并通过 npm 使用它)。 Angular does not have native component or element like that. Angular 没有这样的原生组件或元素。

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

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