angularjs - AngularJs 中的模板准备

标签 angularjs

是否可以使用 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/

相关文章:

unit-testing - 在 AngularJS 单元测试中模拟 $modal

javascript - 在不刷新页面的情况下无法更新 $scope 对象

javascript - ng-repeat limitTo 语法中如何操作

javascript - AngularJS:ng-switch + ng-repeat,在 switch 语句内带有按钮

javascript - 简单的应用程序不绑定(bind)到范围

javascript - 如何使用 Angular JS 访问 JSON 中的嵌套对象

javascript - 检查对象是否在 ng-repeat 中的另一个对象数组中

angularJS:ui-router $state.go 仅适用于第一次点击

angularjs - ng-show 在指令模板中不起作用

angularjs - Angular JS 和 Twitter API,我们如何将它们连接起来