角2 html绑定 [英] angular 2 html binding

查看:90
本文介绍了角2 html绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Angular 2应用程序,它是ASP.NET MVC应用程序的一部分。我想要使​​用ajax加载部分视图并显示它。我有我的控制器设置为此,我可以使ajax调用并获得html响应。但是,如何显示?如果我只是使用绑定语法 {{myVal}} ,则会编码所有html字符(当然)。



我需要以某种方式将div的内部html绑定到变量值。



谢谢!

解决方案

正确的语法现在如下:

 < div [innerHTML] =theHtmlString > 
< / div>

工作在
2.4.0


I am writing an Angular 2 application which is part of an ASP.NET MVC application. I want to be able to use ajax to load a partial view and display it. I have my controller set up for this, and I can make the ajax call and get the html response. However, how do I display it? If I simply use the binding syntax {{myVal}} it encodes all html characters (of course).

I need somehow to bind the inner html of a div to the variable value.

Thanks!

解决方案

The correct syntax is now the following:

<div [innerHTML]="theHtmlString">
</div>

Working in "2.4.0"

这篇关于角2 html绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆