在Angular模型中恢复当前域(ajax调用驻留的角度服务)以准备完整的api url来检索数据

Kar*_*y V 14 api service web angularjs

我们有演示和现场网站当我们部署应用程序演示它应该在的演示工作就像在现场明智的.demo url就像demo.xxxx.com,live就像xxxx.com.

在角服务层我打电话asp.net的WebAPI方法来访问数据.所以,我需要为这个,我需要当前域(应用程序的根路径)准备的URL.这样我就可以将此路径作为webapi路径的前缀,因此我可以调用webapi方法.

Pie*_*len 41

您可以使用$ location服务.

$log.info($location.absUrl());
$log.info($location.protocol() + "://" + $location.host() + ":" + $location.port());
Run Code Online (Sandbox Code Playgroud)

但是,如果您使用以"/"开头的相对URL来访问您的后端,您还应该获得所需的行为.