gpt4 book ai didi

angularjs - 如何使用 AngularJS 发送 HTML 电子邮件?

转载 作者:行者123 更新时间:2023-12-03 06:58:11 25 4
gpt4 key购买 nike

我正在使用cordova电子邮件插件,当我发送简单文本时它可以工作。

但是,我尝试使用模板来构建电子邮件正文。我认为 $compile 可以解决问题,所以我创建了一个点击函数:

    $scope.openShare = function (title,body) {
var templateURL = "templates/roi-email.html";
$http.get(templateURL).success(function(data, status, headers, config) {
var templateRendered = $compile( data )( $scope );

if(window.plugins && window.plugins.emailComposer) {
window.plugins.emailComposer.showEmailComposerWithCallback(function(result) {
console.log("Response -> " + result);
},
title, // Subject
templateRendered, // Body
[], // To
null, // CC
null, // BCC
true, // isHTML
null, // Attachments
null); // Attachment Data
}

但是,templateRendered 不是字符串对象。我认为它是一个 mg-view 对象。

那么如何将“data”中的原始 html 转换为呈现的字符串,即 templateRendered 以传递给电子邮件编辑器?

最佳答案

使用 Angular 元素,不要忘记在使用的范围上触发 $apply:

http://jsfiddle.net/coma/o63wvscn/

app.controller('Main', function($scope, $compile, $timeout) {

var scope = angular.extend($scope.$new(), {
user: {
email: 'foo@foo.com'
}
});

var email = angular.element('<div><p>{{ user.email }}</p></div>');
$compile(email)(scope);

scope.$apply();
alert(email.html());
});

关于angularjs - 如何使用 AngularJS 发送 HTML 电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25835144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com