Issue
I have URL's in project as:
How I can get segments news
, video
from these URL?
I tried to use $location
in Angular JS, but this object has not these segments
Solution
You need to use $location.path()
// given url http://blo.c/news
var path = $location.path();
// => "/news"
If you are using HTML5 mode you must ensure $locationProvider.html5Mode(true) is set so $location
works properly.
If you are not using HTML5 mode (which is the case here); then you'll need to drop to traditional javascript to get the URL, since you are not using Angular routing in the first place:
// given url http://blo.c/news
var path = window.location.pathname;
// => "/news"
You might choose to inject $window instead of using window
directly, this is only a thin wrapper over the native window
object but facilitates testing.
Answered By - seanhodges
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.