Skip to content

Instantly share code, notes, and snippets.

@evertonrobertoauler
Created May 15, 2017 12:37
Show Gist options
  • Save evertonrobertoauler/aed3f2f50694c524d880ad1a5c5838f7 to your computer and use it in GitHub Desktop.
Save evertonrobertoauler/aed3f2f50694c524d880ad1a5c5838f7 to your computer and use it in GitHub Desktop.
Access window
import { PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
@Component({...})
export class DemoComponent implements OnInit {
constructor(@Inject(PLATFORM_ID) private platformId: Object) { }
ngOnInit() {
if (isPlatformBrowser(this.platformId)){
// here you can access window
console.log(window);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment