-
document export class ExampleComponent { constructor(@Inject(DOCUMENT) document: any) { console.dir(document) } }
-
window const WINDOW = new InjectionToken<any>('window', { providedIn: 'root', factory: () => window }); or export class ExampleComponent { constructor(@Inject(WINDOW) window: any) { console.dir(window) } }
Location import { Location } from '@angular/common'; export class AbmNavbarComponent implements OnInit{ // ctor 中注入 Location constructor(private _location:Location){ //... } ngOnInit() { // 打印当前地址 console.log(this._location.path(true)); } }