【发布时间】:2018-05-08 10:50:01
【问题描述】:
我想将我的变量传递到该模板中,让它呈现,然后将生成的 HTML 作为字符串获取。
如何在 AngularJS 中做到这一点?有没有类似render_to_string()function in Django的功能?
问题是我有一个email.html 模板(你知道,布局电子邮件很痛苦),我想用变量填充它。
假设email.html的内容是这样的:
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Hello {{ name }}</h1>
<div>We will contact you soon in this email address: {{ email }}</div>
</body>
</html>
我有一个对象:data = {name: 'Foo', email: 'foo@bar.com' }
然后我会期待类似于:
let messageBodyHtml = render('path_to_email.html', data)
最后,messageBodyHtml 将包含一个包含以下内容的字符串:
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Hello Foo</h1>
<div>We will contact you soon in this email address: foo@bar.com</div>
</body>
</html>
【问题讨论】:
标签: javascript angularjs django render