admin管理员组文章数量:1323035
everyone. Sometimes I need some way to get some part of external site url in my angular code. But there's obviously no way to do it with native angular services, and I don't wanna use some Jquery library for parsing url. I need some service for url parsing which. Where can I find such service? Thx!
everyone. Sometimes I need some way to get some part of external site url in my angular code. But there's obviously no way to do it with native angular services, and I don't wanna use some Jquery library for parsing url. I need some service for url parsing which. Where can I find such service? Thx!
Share Improve this question asked Feb 2, 2014 at 22:06 EriendelEriendel 9791 gold badge9 silver badges23 bronze badges3 Answers
Reset to default 13You can do it in Vanilla JavaScript.
var parser = document.createElement('a');
parser.href = "http://example.:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example."
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.:3000"
Source: https://gist.github./jlong/2428561
I guess you could use the $sce service:
function($scope, $sce) {
$scope.getHtml = function() {
return $sce.trustAsResourceUrl(myUrlHere);
};
}
As mentioned in other post, provided that this is not subject to CORS.
By Parsing, I'm assuming you mean fetching of content/data from a url.
Proving the url allows any domain ( 'Access-Control-Allow-Origin', '*' ) or your domain, Angular does have ajax functions built in, simular to jquery et all.
http://docs.angularjs/api/ng.$http
Copied direct from the anguar doc
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
本文标签: javascriptHow can I parse external link url using native angular codeStack Overflow
版权声明:本文标题:javascript - How can I parse external link url using native angular code? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742107681a2421097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论