是否可以使用 AngularJs 渲染模板而不是在页面上,但可能在内存中?我需要准备 html 以作为电子邮件发送。 我想我可以在隐藏的 div 中渲染一些东西,然后以某种方式将其内容分配给变量,但对我来说它看起来很难看:(
最佳答案
你可以看一下$compile函数:http://docs.angularjs.org/api/ng .$编译
示例:
function MyCtrl($scope, $compile){
// You would probably fetch this email template by some service
var template = '</div>Hi {{name}}!</div></div>Here\'s your newsletter ...</div>'; // Email template
$scope.name = 'Alber';
// this produces string '</div>Hi Alber!</div></div>Here\'s your newsletter ...</div>'
var compiledTemplate = $compile(template)($scope);
};
关于angularjs - AngularJs 中的模板准备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15023537/