[英]mailto protocol on a link opens with HTML tags
I am using the following code in angular JS template to open outlook with some fields pre filled. 我在有角JS模板中使用以下代码来打开带有某些字段的Outlook。
<a href="mailto:{{item.caseOwner}}?subject= Case {{item.caseNumber}}">OWNER</a>
where - 哪里-
item.caseOwner = abc@xyz.com;
This works fine when item.caseOwner
is a string. 当item.caseOwner
是字符串时,此方法工作正常。 But in some scenarios, it comes wrapped in an HTML tag for the highlighting purpose. 但是在某些情况下,为了突出显示目的,它包装在HTML标记中。
item.caseOwner = <span class"highlight">abc@xyz.com<span>;
In this case the outlook opens up with HTML tags and it makes no meaning. 在这种情况下,前景会打开并带有HTML标记,这没有任何意义。 Is there a way to extract the string inside the <span></span>
before the user clicks the link ? 在用户单击链接之前,是否可以提取<span></span>
内部的字符串?
Create a custom filter to cleanup item.caseOwner
. 创建一个自定义过滤器以清理item.caseOwner
。
<a href="mailto:{{item.caseOwner | asEmail }}?subject= Case {{item.caseNumber}}">OWNER</a>
For cleaning up span tags, a search-replace can be implemented like so. 为了清理跨度标签,可以像这样实现搜索替换。
function asEmailFn(emailAddressOrMarkup) {
return emailAddressOrMarkup
.replace(/<[\/]*?span.*?>/g, '');
}
angular.module('App', [])
.filter('asEmail', function() {
return asEmailFn;
})
.controller('TestController', ['$scope', 'asEmail', function($scope, asEmail) {
}]);
Here is how I have done it. 这是我的方法。
In the main parent controller of application ie alias home
在应用程序的主父控制器中,即别名home
home.stripOffHTML = function(itemString){
let localString = itemString;
if(localString){
return localString.replace(/<\/?[^>]+(>|$)/g, "");
}
};
In the HTML code: 在HTML代码中:
<a href="mailto:{{home.stripOffHTML(item.caseOwner)}}?subject=Case {{item.caseNumber}}">OWNER</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.