stackさんの回答とかを参考に自分が使いやすく。
coreApp.filter('parseUrl', function($sce) {
var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/gi;
return function(text, target, style) {
style = style || null;
angular.forEach(text.match(urlPattern), function(url) {
if (style) {
text = text.replace(url, '<a target="' + target + '" href='+ url + ' style="' + style + '">' + url + '</a>');
} else {
text = text.replace(url, '<a target="' + target + '" href='+ url + '>' + url + '</a>');
}
});
return $sce.trustAsHtml(text);
};
});
使い方は引数を見てもらえれば一目瞭然だよね。