Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use $location to to get the protocol host and port of my current url in a factory

How do I get the current protocol host and port of my current url?

app.factory('actionTypeFactory', ['$resource', function($resource, $location){
  return $resource($location.protocol() + '://'+ $location.host() +':'+  $location.port()  +'82/somelocation')
}]);

I would like the url to look like this: http:// localhost:80 /somelocation

like image 450
Amanda Watson Avatar asked Aug 08 '14 15:08

Amanda Watson


People also ask

Which method of $location service is used to get the full URL of the current web page?

absUrl(); This method is getter only. Return full URL representation with all segments encoded according to rules specified in RFC 3986.

How do I find the URL protocol?

The protocol property sets or returns the protocol of the current URL, including the colon (:). For the domain you can use: var domain = window. location.

Which method of $location service is used to get the URL without base prefix?

hash() Method: It is a read and writes method of $location service. It returns the current hash value of the current URL when called without parameters and when called with parameters it returns the$location object.

How to update the URL in AngularJS?

If the user is maximizing it the first time, share the url to this maximized view with the maximizedWidgetId on the UI. As long as you use $location(which is just a wrapper over native location object) to update the path it will refresh the view. Not only $location will refresh the view.


1 Answers

You must inject the $location service, that's why it is undefined:

app.factory('actionTypeFactory', ['$resource', '$location', function($resource, $location){
  return $resource($location.protocol() + '://'+ $location.host() +':'+  $location.port()  +'82/somelocation')
}]);
like image 144
Fedaykin Avatar answered Oct 22 '22 11:10

Fedaykin