Is Angular 2 equivalent to Angular1 $ location.absURL ()?

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

As per Angular 1 documentation, $ location.absUrl (); will return it as such.

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

Methods absUrl (); This method is only the recipient.

Returns a complete representation of the URL with all segments encoded in accordance with the 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" 
+5
source share
2 answers
 import {LocationStrategy} from '@angular/common'; constructor(private location:LocationStrategy) { var fullPath = (<any>this.location)._platformLocation.location.href; } 
+4
source
 <script src="https://code.angularjs.org/2.0.0-beta.9/router.dev.js"></script> import {LocationStrategy} from '@angular/common' // pre RC.2 import {LocationStrategy} from 'angular2/router' constructor(private location:LocationStrategy) { this.location.prepareExternalUrl('http://example.com/#/some/path?foo=bar&baz=xoxo'); } 

Plunger example

+1
source

Source: https://habr.com/ru/post/1246100/


All Articles