stackさんの回答とかを参考に自分が使いやすく。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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); }; }); |
使い方は引数を見てもらえれば一目瞭然だよね。