0

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

3
  • Are you using an angular router? If so doing anything on server to parse path wouldn't make any sense Commented Feb 23, 2016 at 18:39
  • @charlietfl No I am not using an angular router Commented Feb 23, 2016 at 18:40
  • 1
    using an angular router might make your life a lot easier. Commented Feb 23, 2016 at 18:46

1 Answer 1

0

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
};
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.