How To Email Text In Ionic With Javascript

How To Email Text In Ionic With Javascript?

$scope.emailText = function(){
        // replace the targetTextArea with your id
        var textElement = document.getElementById('targetTextArea');
        var formattedBody = textElement.value;;
        var mailToLink = "mailto:x@y.com?body=" + encodeURIComponent(formattedBody);
        window.location.href = mailToLink;
    }