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"
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.
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.
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.
$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
import {LocationStrategy} from '@angular/common';
constructor(private location:LocationStrategy) {
var fullPath = (<any>this.location)._platformLocation.location.href;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With