Set angular.js url root globally

Nebril picture Nebril · Dec 1, 2013 · Viewed 8k times · Source

I have an angular app that is hosted at my university server.

Because the app is not in domain root (urls are constructed as follows: university.domain/~<student_id>) all links and image srcs are broken (angular assumes that it is located in domain root).

My question is: how can I override angular base url so I can still use goodies like ng-href, ng-src etc.?

Answer

francisco.preller picture francisco.preller · Dec 1, 2013

Quoting the AngularJS documentation:

Relative links

Be sure to check all relative links, images, scripts etc. You must either specify the url base in the head of your main html file (<base href="/my-base">) or you must use absolute urls (starting with /) everywhere because relative urls will be resolved to absolute urls using the initial absolute url of the document, which is often different from the root of the application.

More here on the official documentation.

Example

<base href="university.domain/~12345678" />