将angularjs $ scope对象视为html

时间:2016-07-05 14:25:39

标签: javascript html angularjs

我如何将angularjs $ scope对象视为div中的html。我的HTML代码是

{{topicDesc}}

我正在使用

传递topicDesc
var topicdesc1 = "Please ensure you read through <a href="http://adajprod.nce.amadeus.net/ABCHelp/pages/faq_home.html" target="_blank">ABC FAQ </a> and <a href="http://adajprod.nce.amadeus.net/ABCHelp/pages/help_home.html" target="_blank">ABC Help</a> before opening a request."`
$scope.topicDesc = topicDesc1;

scope.topicdesc被视为字符串,它在网页上打印相同的确切句子。我该如何解决这个问题?请帮助我更新鲜。

2 个答案:

答案 0 :(得分:1)

您可以使用angular方法ng-bind-html将此html绑定到视图中。 它应该是这样的:

var topicdesc1 = "Please ensure you read through <a href="http://adajprod.nce.amadeus.net/ABCHelp/pages/faq_home.html" target="_blank">ABC FAQ </a> and <a href="http://adajprod.nce.amadeus.net/ABCHelp/pages/help_home.html" target="_blank">ABC Help</a> before opening a request."`
$scope.topicDesc = topicDesc1;

<div ng-bind-html-unsafe="topicDesc"></div

另请参阅此内容,使用角度link

将HTML插入视图

答案 1 :(得分:0)

使用ng-bind-html-unsafe不是正确的方法,因为它在更高版本中已被弃用。 With ng-bind-html-unsafe removed, how do I inject HTML?将是解决此问题的正确方法。