问题
This is working:
Html
<a href="mailto:?subject={{vm.property.address.streetNumber}}, {{vm.property.address.streetName}} {{vm.cityName}} {{vm.stateName}}%20IPL%20#%20{{vm.property.id}}&body={{comment.note}}">@L("CsEmail")</a>
This is not working:
<a ng-href="{{vm.email}}" ng-click="vm.composeEmail(comment)">@L("CsEmail")</a>
js
vm.composeEmail = function (data) {
vm.email = "mailto:?subject={{vm.property.address.streetNumber}}, {{vm.property.address.streetName}} {{vm.cityName}} {{vm.stateName}}%20IPL%20#%20{{vm.property.id}}&body={{data.note}}";
// I need to save this here
};
Q : I need to save the data after sending the email.Hence I cannot use the first option.But 2nd option is not working.That means it is not opening the outlook. How to do that?
回答1:
We use this from an angular controller:
vm.composeEmail = function (data) {
var email = "mailto:...";
//save here
$window.location.href = email;
};
This way you can save whatever needs to be saved, and then open the mail client from the controller. The html will look something like this:
<a ng-href="" ng-click="vm.composeEmail(comment)">@L("CsEmail")</a>
You also need to break up your 'mailto' string, as thegio suggests.
回答2:
Maybe a better solution:
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<a href="mailto:{{email}}"><span>Email {{email}}</span></a>
</div>
</div>
var myApp = angular.module('myApp',[]);
var MyCtrl = function($scope) {
$scope.email = 'bob@bob.com';
$scope.name = "Bob";
$scope.cc = "test@test.com";
$scope.subject = "this is the subject";
}
I hope it helps.
回答3:
why not directly using the scope vars, like that:
vm.email = "mailto:?subject=" + vm.property.address.streetNumber + ", " + vm.property.address.streetName + " " + vm.cityName + " " + vm.stateName + " " + "IPL# " + vm.property.id + "&body=" + data.note;
did you tried to add target="_blank":
<a ng-href="{{vm.email}}" ng-click="vm.composeEmail(comment)" target="_blank">@L("CsEmail")</a>
回答4:
How about using $window.open('mailto:etc');
inside the function?
回答5:
inside "composeemail" function open a new window
$window.location.href = 'mailto:etc'
and remove the value inside ng-href
来源:https://stackoverflow.com/questions/36553390/open-an-outlook-within-angular-controller