我有一些部分,其中加载了一些网址templates/test.html,例如。此TemplateURL将始终是相对的。我想在网站内的不同位置使用相同的模板。
因此,我想使用相同的相对url http://somedomain.com/templates/Test.html,即使我在http://somedaomian.com/some1/some2的某个实际url上。
我曾尝试使用$loaction服务,但在需要时无法将$loaction重新设置为home url。
例如,在我的控制器中,我想:
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
};发布于 2014-04-21 02:58:42
如果你想要绝对网址,$location.absUrl()将返回所有内容(所有网址段)。
如果您需要主机名,$location.host()将返回主机名。
如果您需要该协议,$location.protocol()将返回该协议。
如果您需要该路径,$location.path()将返回该路径。
如果你想要哈希值,$location.hash()会返回的。
您应该能够使用这些方法来解析出您想要的url片段。
var path = $location.path();
var hash = $location.hash();
var basePath = path.replace(hash, '');https://stackoverflow.com/questions/23186200
复制相似问题