0

I have some partials which are loaded with some URL templates/test.html for example. This TemplateURL will always be relative. I want to use the same templates in different locations within the website.

So , I want to use the same relative url http://somedomain.com/templates/Test.html even if I am on some actual url of http://somedaomian.com/some1/some2

I have tried to use the $loaction service, but I am unable to set the $loaction back to the home url when I need to.

E.g in my controller I would like to :

var new_base_url = homeURL();

function homeUrl() {
   /* Here is where I am unable to get the home url */
   $location.path('/');      // simply returns the current url 

};

1 Answer 1

1

If you want the absolute Url, $location.absUrl() will return everything (all url segments).

If you want the host name, $location.host() will return the host name.

If you want the protocol, $location.protocol() will return that.

If you want the path, $location.path() will return that.

If you want the hash, $location.hash() will return that.

You should be able to use these methods to parse out the pieces of the url that you are after.

var path = $location.path();
var hash = $location.hash();
var basePath = path.replace(hash, '');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I was hoping for a lazy way ... for some reason, $loaction.path() return nothing even if there is a /something/something

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.