How do I get the absolute path of the current page in Angular 2?

后端 未结 5 2040
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 06:34

I\'ve essentially run into this problem, where I need a reference to the current route to use gradients, but have yet to figure out how to translate the solution into Angula

5条回答
  •  攒了一身酷
    2020-11-30 07:14

    You can use the DOCUMENT injection from @angular/common.

    import { Component, Inject } from '@angular/core';
    import { DOCUMENT } from '@angular/common';
    
    @Component({...})
    class SomeComponent {
      constructor(@Inject(DOCUMENT) document: any) {
        console.log(document.location.href);
      }
    }
    

提交回复
热议问题