本文介绍了angular 2中innerHTML内的字符串插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 [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 不支持 Angular 绑定:
You can use TypeScript interpolation. Angular bindings aren't supported in dynamically added HTML:
public data: any = `<a>${stringInterpolation}</a>`;
这篇关于angular 2中innerHTML内的字符串插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!