How to build the function in AngularJS to chceck the last part of the url?
My examples:
#/menu1/123/edit
#/menu2/444/create/new<
This should give you the desired result:
window.alert(window.location.href.substr(window.location.href.lastIndexOf('/') + 1));
You could get the current URL by using: window.location.href Then you only need to get the part after the last '/'
More efficient way:
location.pathname.split('/').slice(-1)[0]
In case of http://example.com/firstdir/seconddir/thirddir?queryparams#hash
; it will give you thirddir
pathname
will keep only the part of url after domain name and
before query params split
will explode the url into array separated by /
slice
will give you array containing only the last item [0]
will you last item as a string (in contrast to item of an
array)