我正在调用一个检索JSON对象的API,并且正在为该对象执行*ngFor。我遇到的问题是其中一个字段是URI编码的,而我不知道如何在*ngFor循环上应用decodeURIComponent。
<div *ngFor="let note of NotesList">
<div class="alert alert-custom">
<h5>{{note.notetitle}}</h5>
<hr>
<div class="smallfont">{{note.notecontent}}</div>
<hr>
<div class="supersmallfont">By {{note.username}} on {{note.dateentered}}</div>
</div>
</div>URI编码的字段不包含任何内容。
有可能从HTML文件中解码吗?谢谢。
发布于 2021-01-18 08:39:02
你不必关心循环,Ivy会帮你处理的。只需在组件中创建一个执行此工作的函数,并在模板中使用它:
decode(content: string){
return decodeUriComponent(content);
}然后在您的html模板中:
<hr>
<div class="smallfont"> {{ decode(note.notecontent) }}</div>
<hr>https://stackoverflow.com/questions/65767430
复制相似问题