Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an Angular 2 equivalent to Angular1's $location.absURL()? [duplicate]

Is there a way to return the full url representation with all segments encoded using Angular 2?

According to the Angular 1 Documentation, $location.absUrl(); will return it as such.

https://docs.angularjs.org/api/ng/service/$location

Methods absUrl(); This method is getter only.

Return full url representation with all segments encoded according to rules specified in RFC 3986.

// given url http://example.com/#/some/path?foo=bar&baz=xoxo 
var absUrl = $location.absUrl();  
// => "http://example.com/#/some/path?foo=bar&baz=xoxo"
like image 473
chustedt Avatar asked Mar 30 '16 20:03

chustedt


People also ask

What is the use of $location in angular?

The $location is an AngularJS service used to get the current web page information. The $location reflect the current web page URL, the changes in the URL will be reflected in the $location service and vice versa. To get the absolute URL. To get or set the URL path or hash. To get the current URL protocol. To get the current URL Host.

How to get the absolute URL of the page in AngularJS?

The ng-controller is a directive to control the AngularJS Application. The “locCtrl” used to create the controller for the Application with arguments $scope object and $location service. The $location.absUrl (); is used to get the absolute URL of the page. The $location.url (); is used to get the URL of the page.

What is ng-controller in AngularJS?

The ng-controller is a directive to control the AngularJS Application. The “locCtrl” used to create the controller for the Application with arguments $scope object and $location service. The $location.absUrl (); is used to get the absolute URL of the page.

What is $locationchangesuccess broadcast in angular event?

$locationChangeSuccess Broadcasted after a URL was changed. The newStateand oldStateparameters may be defined only in HTML5 mode and when the browser supports the HTML5 History API. Type: broadcast Target: root scope Parameters Param Type Details angularEvent Object Synthetic event object. newUrl


1 Answers

import {LocationStrategy} from '@angular/common';

constructor(private location:LocationStrategy) {
  var fullPath = (<any>this.location)._platformLocation.location.href;
}
like image 146
Michal Rozumný Avatar answered Oct 09 '22 03:10

Michal Rozumný