【问题标题】:Displaying or nesting variables within a variable: Cordova, Ionic, emailComposer在变量中显示或嵌套变量:Cordova、Ionic、emailComposer
【发布时间】:2016-05-10 23:48:39
【问题描述】:

我正在使用 Cordova + Ionic framework(使用 AngularJS)+emailComposer plugin 创建一个表单样式的移动应用程序。

这个想法是用户填写一些下拉菜单、单选框等;然后点击一个按钮,该按钮使用 emailComposer 将响应数据加载在一些预定义的 HTML 中,以在手机的本机电子邮件应用程序中的某个位置发送电子邮件,用户需要使用该应用程序。

我有一个变量 $scope.foo 将一些 HTML 加载到电子邮件正文中,问题是我需要将其他响应数据(变量)嵌套到该变量中。 (我不能让 emailComposer 接受这个变量)。

问题是如何在另一个 $scope 变量中的某个 HTML 中显示 $scope 变量?

由于 emailComposer 没有使用 AngularJS,我认为我无法继续使用 {{piping}}。

var exampleApp = angular.module('starter', ['ionic', 'ngStorage'])


exampleApp.controller("EmailController", function($scope) {

    $scope.someVariable = "whatever";
    $scope.anotherVariable = "something";

    $scope.foo = "<h1>I want to insert the two variables here: {{$scope.someVariable}} and here: {{$scope.anotherVariable}} in some nice HTML</h1>";

    $scope.sendEmail = function() {
        if(window.plugins && window.plugins.emailComposer) {
            window.plugins.emailComposer.showEmailComposerWithCallback(function(result) {
                console.log("Email Sucess");
            },
                "subject here",                         //subject line
                $scope.foo,                             //body
                ["someone@example.com", "some.else@example.com"],   //to
                null,                                   //CC
                null,                                   //BCC
                true,                                   //isHTML
                null,                                   //attachments
                null                                    //attachment data
            );
        }
    }
});

【问题讨论】:

    标签: javascript html angularjs cordova ionic-framework


    【解决方案1】:

    您可以使用类似 var emailBody=$scope.$eval($scope.foo) 的方法,然后将 emailBody 变量传递给您的 sendEmail 函数。这可能不是 100% 正确,但基本上,评估身体然后传递结果似乎是正确的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-01
      • 2015-08-10
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多