javascript - AngularJS - 在 html 模板中使用插值

标签 javascript html angularjs

不确定以前是否有人遇到过这种情况,在谷歌上查找我似乎找不到例子。基本上,我正在创建一个很长的 html 模板,并将其包装在 ng-bing-html 中,它加载我的 html,但它不加载我的插值。让我给你一个简单的例子:

Controller :

$scope.example_text_here = "Hello World!"
$scope.HTML_template = "<p><strong> Example: </strong> {{ example_text_here }}</p>"

HTML:

<div ng-bind-html="HTML_template"></div>

输出

Example: {{ example_text_here }}

我的期望:

Example: Hello world!

有人知道如何实现这一点吗?

最佳答案

您应该使用 $interpolate 模块,然后注入(inject)当前范围甚至 $compile。查看更多https://docs.angularjs.org/api/ng/service/ $插值

$interpolate($scope.HTML_template)($scope)

关于javascript - AngularJS - 在 html 模板中使用插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52518070/

相关文章:

javascript - GM_xmlhttp请求 : Why is it never firing the onload in Firefox?

Javascript OOP,从其他嵌套方法访问方法

javascript - 根据单击的链接更改表格内容

angularjs - 如何在jsf页面中使用AngularJS

javascript - 简单的功能和值的改变

javascript - 第一个选项卡面板不显示网格中的数据(IE 9)

html - 如何使用 thymeleaf 从一页中删除 html 片段?

javascript - 如何修复无法正常工作的 HTML5 视频 Javascript 跟踪代码

javascript - 如何使用 $http 为 Rest API 调用创建通用服务?

angularjs - 如何仅使用 shift+return 启用回车