How to get base url in angular 5?

前端 未结 9 954
抹茶落季
抹茶落季 2020-12-06 04:01

My current url is http://localhost:4200/test/dashboard.

I want to print base url i.e http://localhost:4200 using angular 5 features.

9条回答
  •  猫巷女王i
    2020-12-06 04:29

    You can Try (Can Get all Detail of current location)

    import { Component, OnInit } from '@angular/core';
    import { Location } from '@angular/common';
    
    @Component({
     selector: 'some-component',
     templateUrl: './component.html',
     styleUrls: ['./component.scss']
    })
    
    export class SomeComponent implements OnInit {
    
     constructor(location: Location) {}
    
        ngOnInit() {
            console.log(this.location._platformStrategy._platformLocation.location);  
        }
    }
    

提交回复
热议问题