Answers for "angular window object"

2

nangular make window available

import { Inject } from '@angular/core';
import { DOCUMENT } from '@angular/common';

export class MyClass {

  constructor(@Inject(DOCUMENT) private document: Document) {
     this.window = this.document.defaultView;
  }

  check() {
    console.log(this.document);
    console.log(this.window);
  }

}
Posted by: Guest on June-24-2020
0

angular window object

// in app.module.ts
providers: [
{ provide: Window, useValue: window }
]

// in component: 
Then you can just inject it directly anywhere you want - e.g. in a service:

constructor(private window: Window) {
// ...
Posted by: Guest on July-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language