0

I have a symphony built, in which I have a page working with Angularjs 1.5.*.

I'm not using the angularjs route so I don't have the variables there.

My url is (and might change where the 16 is, though always at the end of url):

www.mydomain.com/billing/detail/16

I want to get the 16 from the url.

Just want to get that number and handle it in my controller so I can call a symphony controller and get the data I currently have hardcoded.

Thanks !!!!

Simon Berton
  • 383
  • 2
  • 11

5 Answers5

2

You can use window.location object.

location.pathname.split("/").pop()
Ninja
  • 1,920
  • 1
  • 22
  • 27
0

If you do not want to use $routeParams, you could try to get the url using

$location.absUrl();

and then parse it to get the value you need.

Fjut
  • 1,264
  • 10
  • 23
0

you should use $stateParams. like $somevar = $stateParams.urlParamName;

0

You can extract the Url into a string using like below:

var url = new URI('www.mydomain.com/billing/detail/16'); 

url.path(); which will return '/billing/detail/

Then you can just use split like this:

var url = "www.mydomain.com/billing/detail/16";

$scope.myvalue = getUrlID(url);

function getUrlID(str) {
    return str.split('www.mydomain.com/billing/detail/')[1];
}

Here is a Plunker. Of course it is hardcoded in the plunker because I can't access your URL, but this should get you going.

Rani Radcliff
  • 4,622
  • 5
  • 29
  • 53
0
$location.absUrl().split("/").pop()
The Hungry Dictator
  • 3,352
  • 5
  • 38
  • 48
  • Should have been a comment! If you don't have enough score to add comments, add more details to support your answer. Flagged in [reviews](https://stackoverflow.com/review/first-posts/16555520) – harshavmb Jun 28 '17 at 17:15