This angular filter will also work!
This is really cool and simple because it uses browsers created in URI parsing, rather than relying on a regular expression.
angular.module('myCoolApp') .filter('urlFilter', function ($document) { return function (input) { var parser = document.createElement('a'); parser.href = input; return parser.hostname; }; });
You can implement it in your view as follows.
{{ myLongURL | urlFilter }}
If myLongURL http://www.example.com/page-with-a-long-long-long-OMG-so-long-name.html , then it will be displayed as example.com after passing through the filter. If you want www. in the beginning, you can just do it!
www.{{myLongURL | urlFilter}}
source share