javascript - How to remove "http://" from domain name inside view -
how can remove "http://" beginning of url inside view in angularjs app?
i have urls in database like:
http://example.com/ http://example.com example.com
but need show
example.com
inside view.
this deals http , https or other url. uses built-in url class, handle of things haven't thought of correctly.
app.filter('domain', function () { return function (input) { try { var url = new url(input); return url.hostname; } catch (domexception) { // malformed url. return original (or else). return input; } }; });
urls correct , might not have thought of:
- http://example.com
- http://example.com:8000
- http://me@example.com
- file://example.com
- https://example.com
- http://example.com/some-path
- http://example.com?some-query-url
you may not need them now, using correct library function means app won't break unexpectedly in future when tries use else.
Comments
Post a Comment