Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

In angular I'm using the http service (get). I need to get the CURRENT url parameters to form the url of the http get. What is the best way to do this?

For example: the page I'm currently on is www.blah.com/blah1/blah2

I need to make a http get request in Angular with a url using blah1 and blah2 parameters. 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. Then in jade, initialize using ng-init with the passed in url parameters. Then I could access those ng-init variables (parameters) inside Angular?

Edit: I am an absolute beginner

share|improve this question
    
Are you using an angular router? If so doing anything on server to parse path wouldn't make any sense – charlietfl 20 hours ago
    
@charlietfl No I am not using an angular router – shapiro 20 hours ago
1  
using an angular router might make your life a lot easier. – Jhecht 20 hours ago

you can write your own wrapper for this requests getting url and you can parse them via this code ;

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
};
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.