[英]How to get URL parameters in Angular JS, Node JS, Express
In angular I'm using the http service (get). 在角度我正在使用http服务(获取)。 I need to get the CURRENT url parameters to form the url of the http get.
我需要获取CURRENT网址参数以形成http get的网址。 What is the best way to do this?
做这个的最好方式是什么?
For example: the page I'm currently on is www.blah.com/blah1/blah2 例如:我当前所在的页面是www.blah.com/blah1/blah2
I need to make a http get request in Angular with a url using blah1 and blah2 parameters. 我需要使用blah1和blah2参数使用url在Angular中发出http get请求。 For example:
例如:
$http.get('www.lala.com/+blah1+blah2)
One solution I was thinking of: Use Node to pass in the url parameters to jade. 我想到的一种解决方案:使用Node将url参数传递给jade。 Then in jade, initialize using ng-init with the passed in url parameters.
然后在玉器中,使用ng-init和传入的url参数进行初始化。 Then I could access those ng-init variables (parameters) inside Angular?
然后我可以在Angular中访问那些ng-init变量(参数)?
Edit: I am an absolute beginner 编辑:我是一个绝对的初学者
you can write your own wrapper for this requests getting url and you can parse them via this code ; 您可以为获取URL的请求编写自己的包装器,并通过此代码对其进行解析;
function parseURL(url) {
var parser = document.createElement('a'),
searchObject = {},
queries, split, i;
// Let the browser do the work
parser.href = url;
// Convert query string to object
queries = parser.search.replace(/^\?/, '').split('&');
for( i = 0; i < queries.length; i++ ) {
split = queries[i].split('=');
searchObject[split[0]] = split[1];
}
return {
protocol: parser.protocol,
host: parser.host,
hostname: parser.hostname,
port: parser.port,
pathname: parser.pathname,
search: parser.search,
searchObject: searchObject,
hash: parser.hash
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.