I have an input box and what ever is sent is displayed below using angular.js but if the input is a http url i am trying to convert it to a link. I referred to How to replace plain URLs with links? this SO page..
I am able to convert it to the tag but its not a link. Its just like any other text..
Fiddle link :http://jsfiddle.net/JY3Za/1/
The HTML code :
<div ng-app>
<div ng-controller="URL">
<form ng-submit="addTodo()">
<input type="text" ng-model="save" size="30"
placeholder="enter a url"/>
<input class="btn-primary" type="submit" value="add"/>
</form>
<h1>{{replaceURLWithHTMLLinks(show)}}</h1>
</div>
</div>
and the JS code..
function URL($scope) {
$scope.shoe="";
$scope.addTodo = function() {
$scope.show=$scope.save;
$scope.replaceURLWithHTMLLinks=function(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
return text.replace(exp,"<a href='$1'>$1</a>");
};
};
}
PS: I didnt write the regular expression and it was taken from the above Stackoverflow link for testing..