如何使用AngularJS发送HTML电子邮件? [英] How to send HTML email with AngularJS?

查看:279
本文介绍了如何使用AngularJS发送HTML电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cordova电子邮件插件,当我发送简单文本时,该插件可以工作.

I am using a cordova email plugin in that works when I send simple text.

但是,我试图改为使用模板来构造电子邮件的正文. 我以为$ compile可以解决问题,所以我创建了一个on click函数:

However, I am trying to instead use a template to construct the body of the email. I thought $compile would do the trick so I created an on click function:

    $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对象.

However, templateRendered is not a string object. I think it is an mg-view object.

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

So how do covert the raw html in 'data' to a rendered string to i.e., templateRendered to pass to the email composer?

推荐答案

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

Use an angular element and don't forget to trigger the $apply on the used scope:

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发送HTML电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆