加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 动态电子邮件的Angular $compile模板

发布时间:2020-12-17 08:46:18 所属栏目:安全 来源:网络整理
导读:我正在尝试在其中加载带有ng-repeats的html模板,然后使用$compile服务来编译它并在电子邮件中使用已编译的html. 问题……好问之前让我设置术语…… 绑定占位符:{{customer.name}} 约束力:’john doe’ 使用$interpolate我得到实际的绑定值但不适用于ng-rep
我正在尝试在其中加载带有ng-repeats的html模板,然后使用$compile服务来编译它并在电子邮件中使用已编译的html.

问题……好问之前让我设置术语……
绑定占位符:{{customer.name}}
约束力:’john doe’

使用$interpolate我得到实际的绑定值但不适用于ng-repeats.

示例:var html = $interpolate(‘< p> {{customer.name}}< / p>‘)($scope)
返回:’< p> john doe< / p>‘
Ng-repeats不起作用

使用$compile我得到绑定占位符,即{{customer.name}},但我需要的是绑定值’john doe’.

示例:var html = $compile(‘< p> {{customer.name}}< / p>‘)($scope)
返回:’< p> {{customer.name}}< / p>‘

一旦我追加到页面,我就会看到绑定值.但这是用于电子邮件而不是页面加上它具有ng-repeats,$compile可以编译

如何创建一个动态电子邮件模板,在编译后,它会返回带有绑定值的html而不仅仅是绑定占位符,以便我可以将其作为电子邮件发送?

使用$compile是正确的方法.但是,$compile(模板)($scope)不会产生您期望的内插 HTML.它只是将编译的模板链接到要在下一个$摘要期间插值的范围.要获得所需的HTML,您需要等待插值发生,如下所示:
var factory = angular.element('<div></div>');
factory.html('<ul ng-repeat="...">...</ul>');
$compile(factory)($scope);

// get the interpolated HTML asynchronously after the interpolation happens
$timeout(function () {
  html = factory.html();
  // ... do whatever you need with the interpolated HTML
});

(工作CodePen示例:http://codepen.io/anon/pen/gxEfr?editors=101)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读