2014-09-14 6 views
2

나는 간단한 텍스트를 보낼 때 작동하는 cordova 이메일 플러그인을 사용하고 있습니다.Agularjs에서 HTML 전자 메일을 보내는 방법은 무엇입니까?

그러나 대신 전자 메일 본문을 구성하기 위해 템플릿을 사용하려고합니다. 는 내가 클릭 기능상의를 생성하므로 $ 컴파일 트릭을 할 것이라고 생각 :

$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 객체라고 생각한다.

'데이터'의 원시 html을 렌더링 된 문자열, 즉 templateRendered로 변환하여 이메일 작성자에게 전달하는 방법은 무엇입니까?

답변

4

각도 요소를 사용하고, 사용 범위에 $ 적용을 트리거하는 것을 잊지 마세요 :

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

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

    var scope = angular.extend($scope.$new(), { 
     user: { 
      email: '[email protected]' 
     } 
    }); 

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

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

$compile 반환 DOM 요소; 끈이 아니야. 따라서 templateRendered.html() (jQuery)에 액세스하여 콘텐츠를 가져올 수 있습니다. 그러나 the doc과 같이 말한다 : $의 호출은 일반적으로 자동 각도에 의해 이루어집니다 을 소화 할 때까지 업데이트되지 않습니다

뷰를 연결 한 후.

templateRendered.html()에 액세스하기 전에 현재 요약주기가 끝나기를 기다려야합니다. 더 당신이 여기 https://docs.angularjs.org/api/ng/function/angular.element 볼 수 있듯이, HTML 방법은 이미 jqLite에 포함되어, http://plnkr.co/edit/cYsS1c7GbEVRP7RODHvx?p=preview

+0

아니 :

는 작업 예제를 참조하십시오 모든 jQuery를 추가해야합니다. Btw, 오염을 피하기 위해 새로운 범위의 사용을 고려하십시오. – coma

관련 문제