本文介绍了innerHTML内部的字符串插值(角度2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在[innerHTML]
指令中呈现表达式:
How can I render an expression inside an [innerHTML]
directive:
public stringInterpolation: string = 'title';
public data: any = '<a>{{stringInterpolation}}</a>';
<div [innerHTML]="data"></div>
字符串插值被呈现为文本,而不是确切的值.
String interpolation is being rendered as text not the exact value.
这背后的逻辑是我正在使用一个可重用的表,并且我想要一个配置,在该配置中,我可以指定一个将在单元内生成的模板,而不是将所有数据都列为文本.
Logic behind this is I am using a reusable table and I want a configuration where in I can specify a template that will be generated inside a cell rather than listing all data as text.
推荐答案
您可以使用TypeScript插值.动态添加的HTML不支持角度绑定:
You can use TypeScript interpolation. Angular bindings aren't supported in dynamically added HTML:
public data: any = `<a>${stringInterpolation}</a>`;
这篇关于innerHTML内部的字符串插值(角度2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!