Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular-如何将Angular变量绑定到html并显示_Angular_Typescript - Fatal编程技术网

Angular-如何将Angular变量绑定到html并显示

Angular-如何将Angular变量绑定到html并显示,angular,typescript,Angular,Typescript,我有一个组件,它有一个ts文件,它包含html内容作为变量 para1=更多内容 我需要像html本身一样用html绑定这个段落 如何实现这一点?如果变量值包含HTML模板,只需使用innerHTML 像这样- para1= "<a href="www.google.com">sitename</a> more content" para1=“更多内容” 在html文件中- <span [innerHTML]='para1'></span>

我有一个组件,它有一个ts文件,它包含html内容作为变量

para1=
更多内容

我需要像html本身一样用html绑定这个段落


如何实现这一点?

如果变量值包含HTML模板,只需使用
innerHTML

像这样-

para1= "<a href="www.google.com">sitename</a> more content"
para1=“更多内容”
在html文件中-

<span [innerHTML]='para1'></span>

您可以使用来实现这一点

在您的示例中,
para1='…',您可能有以下内容:

<ng-template 
    dynamic-template
    [template]="para1"
>
</ng-template>
可能重复的
import { NgxDynamicTemplateModule } from 'ngx-dynamic-template';

@NgModule({
    imports: [NgxDynamicTemplateModule.forRoot()]
})