Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retreving current domain in Angular model (angular service where ajax calls reside) to prepare full api url to retrieve data

We have demo and live sites when we deploy application to demo it should work in demo like wise in live. demo url will be like demo.xxxx.com and live will be like xxxx.com.

In angular service layer i'm calling asp.net webapi methods to access data. So I need to prepare url for this I need current domain (app root path). So that I can prefix this path to the webapi path hence I can call webapi method.

like image 804
Karunaker Reddy V Avatar asked Apr 15 '14 08:04

Karunaker Reddy V


1 Answers

You can use the $location service for that.

$log.info($location.absUrl());
$log.info($location.protocol() + "://" + $location.host() + ":" + $location.port());

But if you use relative URLs starting with a '/' to access your back-end, you should also get the behavior you want.

like image 176
Pieter Herroelen Avatar answered Nov 16 '22 02:11

Pieter Herroelen