【发布时间】:2014-10-13 19:15:35
【问题描述】:
如何将文本URL 转换为linkable?我用过angular-sanitize.min.js (1.2.11)。我从第一次部署就一直在使用这个版本。
angular-sanitize 适用于具有正确格式的文本,例如:如果它以 http/https/ftp/email 开头,但不适用于 www。
我想将以下文本 URL 显示为可链接的,它不是由 angular-sanitize 转换的。
1) www.stackoverflow.com
2) stackoverflow.com
3) WWW.STACKOVERFLOW.COM
4) 堆栈溢出.COM
URL's 以上显示为普通文本。
这是我尝试过的代码:
var app = angular.module('app', [
'ngRoute',
'ngSanitize'
]);
app.controller('Controller', [
'$scope',
'$http',
'service',
function ($scope, $http, service) {
//calling service to fetch data from service.
}]);
app.service('service', function () {
this.fetch = function($scope, $http) {
//contact server and get address.
$scope.httpurl = address;
}
};
我的 HTML 有以下代码
<div id="linky-target">
<div ng-bind-html="httpurl | linky:'_blank'">
{{httpurl}}
</div>
</div>
我尝试过使用link,但没有成功。 如何将上述指定格式的 URL 设为可链接?任何帮助表示赞赏。
【问题讨论】:
-
url 的正则表达式硬编码在linky.js#L107。如果你想支持这些 url,你必须找到一个合适的正则表达式,并且可以像
linky那样做。
标签: html angularjs hyperlink angularjs-directive angular-ui